Connecting new events
Introduction
Connecting instance level events is achieved through the method "events->connect" while connecting static events is achieved through the static method "PorteEvents::connect".
Connecting an instance level event
Depending on wether the registered listener is a function or a method, the "connect" method accept two sets of arguments.
Registering a listener function:
function beforeOnCreateListener(){
print 'Method call';
}
$user = new User();
$user->events->connect(
'record_create_before',
'beforeOnCreateListener'
);
$user->save();
Registering a listener method:
class Listener{
function beforeOnCreateListener(){
print 'Method call';
}
}
$listener = new Listener();
$user = new User();
$user->events->connect(
'record_create_before',
array($listener,'beforeOnCreateListener')
);
$user->save();
Complete list of ways to connect events
Connecting an instance event:
$user->events->connect('action',array(object,'method'));
Connecting a global event:
PorteEvents::connect('action','function');
PorteEvents::connect('action',array($object,'method'));
PorteEvents::connect('action',array('Class','method'));
Connecting a records event:
PorteRecord::connect('record_type','action','function');
PorteRecord::connect('record_type','action',array($object,'method'));