on() public static method
Attaches an event handler to a class-level event.
When a class-level event is triggered, event handlers attached to that class and all parent classes will be invoked.
For example, the following code attaches an event handler to ActiveRecord's afterInsert event:
Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_INSERT, function ($event) {
Yii::trace(get_class($event->sender) . ' is inserted.');
});
The handler will be invoked for EVERY successful ActiveRecord insertion.
For more details about how to declare an event handler, please refer to yii\base\Component::on().
See also off().
| public static void on ( $class, $name, $handler, $data = null, $append = true ) | ||
|---|---|---|
| $class | string |
The fully qualified class name to which the event handler needs to attach. |
| $name | string |
The event name. |
| $handler | callable |
The event handler. |
| $data | mixed |
The data to be passed to the event handler when the event is triggered. When the event handler is invoked, this data can be accessed via yii\base\Event::$data. |
| $append | boolean |
Whether to append new event handler to the end of the existing handler list. If |
Please login to continue.