Difference between revisions of "Gallery3:Developer Handbook:Events" - Gallery Codex
Personal tools

Difference between revisions of "Gallery3:Developer Handbook:Events"

From Gallery Codex

Line 12: Line 12:
 
* [http://docs.kohanaphp.com/general/events Kohana has its own events] which modules can listen to, but in general this is discouraged.  For most significant Kohana events there’s a matching Gallery event which your module can listen for instead.
 
* [http://docs.kohanaphp.com/general/events Kohana has its own events] which modules can listen to, but in general this is discouraged.  For most significant Kohana events there’s a matching Gallery event which your module can listen for instead.
  
[[Category:Gallery 3:Developer Handbook Events]]
+
[[Category:Gallery 3:Developer Handbook|Events]]

Revision as of 13:22, 13 June 2011

Events

Because Gallery 3 is modular in its nature, it’s important to let modules be loosely coupled. Tight bindings between modules (where one module directly calls into another one) reduces modularity and limits the possible ways that Gallery 3 can be deployed.

In Gallery 3, this loose coupling is accomplished by using an event system. Modules can publish arbitrary events whenever they choose, and any other module can listen for that event and take action on it. The gallery module has a set of events that it publishes, and many modules listen for and take action on these events. Event Reference

To implement an event listener for your module, you must create a special kind of helper called example_event. Any event that’s triggered will result in a static method call to this helper. For example, when an Item_Model is saved it will generate a “item_updated” event. This will attempt to call example_event::item_updated(). The item_updated() event takes two arguments, the original Item_Model and the newly updated Item_Model so the event handler can figure out what changed and take an appropriate action.

Notes about events:

  • Each event can specify the number and type of its arguments.
  • Module event handlers are called in the order that the modules were activated. You should not count on the module order
  • Kohana has its own events which modules can listen to, but in general this is discouraged. For most significant Kohana events there’s a matching Gallery event which your module can listen for instead.
advertisements