Almost any framework has such concept as system events (triggers, hooks, traps). In joomla they are implemented as plugins. And in the classical literature they are usually called Observers or listeners.
Here is what they do. Event triggers are placed in various places in the code. For example, item:deleted event will be triggered after any item is deleted. All functions that are connected to this event will be executed in order of their connection. Thus, things related to an item will be deleted as well, such as images or database records.
Everything is made pretty easy within ZOO (actually, like in Joomla itself) and is gathered in a single event helper.
Creating and connecting an event class.
$event = $this->app->event; $dispatcher = $event->dispatcher; // registering our class $event->register('MyEventClass'); // connecting to the event $dispatcher->connect('myevent:function', array('MyEventClass', 'handler'));
If you want to create your own event then it’s all the same, just don’t forget to call dispatcher notification.
$dispatcher->notify($event->create($var, 'myevent:function', array( /* assoc array with additional parameters */))); // $var - main object of the event
// A class should be connected manually class MyEventClass { /** * Simple event handler * @param AppEvent $event */ public static function handler($event) { $app = App::getInstance('zoo'); // do not forget that this is a static method without $this $subject = $event->getSubject(); // getting an event object $params = $event->getParameters(); // getting additional parameters } }
JBZoo registers empty classes to simplify functionality enhancement. They can be found here - /media/zoo/applications/jbuniversal/framework/events/jbevent.*.php
. This way you can also find out what kind of events a system has.
Visit our special JBZoo tech support forum which is specifically meant for JBZoo so the priority of the response and its promptness are much better there than in any other place. With inactive account with a “Plus” sign in a tariff plan you can ask for support in one of these sections or use any of our contacts.