SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 184 | Next

James Kennard

"Mastering Joomla! 1.5 Extension and Framework Development"

In addition to these, we can use
our own events. We do not have to define events; we can just use them.
Let's imagine we have a component, which displays information about an entity
called Foobar. We might choose to use a custom event called onPrepareFoobar to
allow listeners to perform any additional processing to the Foobar data before we go
ahead and display a Foobar.
To issue an event, we trigger it. There is a method in the application called
triggerEvent(), which triggers events in the global event dispatcher, notifying
the relevant listeners. This is a pass-through method for the JEventDispatcher
trigger() method.
The triggerEvent() method accepts two parameters: the name of the event and an
array of arguments to pass to the listener.
Imagine we want to trigger the event onPrepareFoobar. This example shows how
we can achieve this; it assumes $foobarData is an object that represents a Foobar
entity. Note that $mainframe is the application.
$arguments = array(&$foobarData);
$result = $mainframe->triggerEvent('onPrepareFoobar', $arguments);
Plugin Design
[ 138 ]
The most important thing to notice here is that we reference and wrap $foobarData
in an array.


Pages:
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196