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 successfu