You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Creating an event simply sets a callback to be invoked if and only if during the execution of the current program such an event is triggered. This is useful if you require notification of certain action throughout your applications.

Registering an Event

Registering an events will allow your callback to be notified when such an event is triggered. Any controller or model that inherits from AppController or AppModel will already have access to the event handler and can immediately begin registering events.

Your model or controller
$this->Events->register("EventName", array($this, "callbackMethod"));

In the above example, when the "EventName" event is triggered the "callbackMethod" will be invoked on the object that registered the event. If you're working from a separate location that doesn't inherit from AppController or AppModel, you can load the Event handler manually.

Manually loading the Event handler
// Load the Event handler
Loader::load(COMPONENTDIR . "events" . DS . "events.php");
$this->Events = new Events();

An event can be registered more than once

If you register the same event with the same callback more than once that callback will be executed multiple times each time the event is triggered.

  • No labels