Browse Source

Added info about class-level event handlers to doc

tags/2.0.0-beta
Alexander Makarov 11 years ago
parent
commit
474d4aeaaf
  1. 9
      docs/guide/upgrade-from-v1.md

9
docs/guide/upgrade-from-v1.md

@ -106,6 +106,15 @@ Yii::$app->on($eventName, $handler);
Yii::$app->trigger($eventName);
```
If you need to handle all instances of a class instead of the object you can attach a handler like the following:
```php
Event::on([ActiveRecord::className, ActiveRecord::EVENT_AFTER_INSERT], function ($event) {
Yii::trace(get_class($event->sender) . ' is inserted.');
});
```
The code above defines a handler that will be triggered for every Active Record object's `EVENT_AFTER_INSERT` event.
Path Alias
----------

Loading…
Cancel
Save