You can check for available core events in class ''Am_Event''. There are many constants defined for events. Also, please note that different events may receive difference event objects (all derived for Am_Event parent). For example, event ''userBeforeInsert'' will receive object of ''Am_Event_UserBeforeInsert'' as parameter.

You can check for available core events in class ''Am_Event''. There are many constants defined for events. Also, please note that different events may receive difference event objects (all derived for Am_Event parent). For example, event ''userBeforeInsert'' will receive object of ''Am_Event_UserBeforeInsert'' as parameter.

−

There is list of currently available events:

+

Here is a list of currently available events:

<source lang="php">

<source lang="php">

class Am_Event

class Am_Event

Revision as of 19:16, 14 September 2012

aMember Pro provides a flexible mechanism to change or add new behaviour to existing actions. It utilises the well-known [Observer] programming pattern.

To wait for an event the code must set up a "hook". Then, on some occasion, the core code or add-on code(!) sends Events (instances of Am_Event class or successors) to all interested parties. Parties handle events by executing pieces of code and, for some events, by adding return values to an event object. Then, the event object is returned to the called core code where it can be inspected and used. It is lengthy to explain, but easy to understand by example:

Setting Hooks. Method 1 - from any part of code

<?php// you can enter this example to am/application/configs/site.php// define handlers for an eventfunction my_custom_function1(Am_Event $event){$event->addReturn($event->getX()+1);}function my_custom_function2(Am_Event $event){$event->addReturn($event->getX()+2);}// setup hooks
Am_Di::getInstance()->hook->->add('myCustomEvent','my_custom_function1')->add('myCustomEvent','my_custom_function2');// now raise the event with variable x = 5 and get returned event object$event= Am_Di::getInstance()->hook->call('myCustomEvent',array('x'=>5));// now check the return. it will be array(5+1, 5+2) == array(6, 7)
print_rr($event->getReturn());

Setting Hooks. Method 2 - from a plugin or a module

You do not need to set up a hook in the plugin explicitly. Just add a plugin named onHookname() to the plugin class, and, if the plugin is enabled and configured, the hook will be set up automatically.

Example continues: within am/application/configs/site.php

// now raise the event with variable x = 5 and get returned event object$event= Am_Di::getInstance()->hook->call('myCustomEvent',array('x'=>5));// now check the return. it will be array(5+1, 5+2) == array(6, 7)
print_rr($event->getReturn());

Available Events

You can check for available core events in class Am_Event. There are many constants defined for events. Also, please note that different events may receive difference event objects (all derived for Am_Event parent). For example, event userBeforeInsert will receive object of Am_Event_UserBeforeInsert as parameter.