on()
on(string|\Cake\Event\EventListenerInterface|null $eventKey = null, array|callable $options = array(), callable|null $callable = null) : $this
Adds a new listener to an event.
A variadic interface to add listeners that emulates jQuery.on().
Binding an EventListenerInterface:
$eventManager->on($listener);
Binding with no options:
$eventManager->on('Model.beforeSave', $callable);
Binding with options:
$eventManager->on('Model.beforeSave', ['priority' => 90], $callable);
Parameters
string|\Cake\Event\EventListenerInterface|null | $eventKey | The event unique identifier name
with which the callback will be associated. If $eventKey is an instance of
Cake\Event\EventListenerInterface its events will be bound using the |
array|callable | $options | Either an array of options or the callable you wish to
bind to $eventKey. If an array of options, the |
callable|null | $callable | The callable function you want invoked. |
Throws
- \InvalidArgumentException
When event key is missing or callable is not an instance of Cake\Event\EventListenerInterface.