Skip to content
Yii2 extension. Attaches events to all ActiveRecord and Controller instances.
Branch: master
Clone or download
Latest commit 0b93904 Aug 6, 2014
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore event module changes Jul 18, 2014
EventBootstrap.php event module changes Jul 18, 2014
EventManager.php going to 2.0 Aug 6, 2014
LICENSE event module changes Jul 18, 2014 added additional data and variable appending Jul 29, 2014
composer.json event module changes Jul 18, 2014

Yii2 event manager component

Attaches events to all application models in a very simple way. You just list your event handlers in config/_events.php this way: [ 'event\sender\ClassName' => [ 'eventName' => [ 'event\handler\ClassName' => 'methodName' ] ] ];

See example below.


The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist bariew/yii2-event-component "*"

or add

"bariew/yii2-event-component": "*"

to the require section of your composer.json file.


    Define app component in main config components section like in this example: 
    'components' => [
          'eventManager'=> [
              'class'     => 'bariew\eventManager\EventManager',
              'events'    => [
                  'app\models\User' => [
                      'afterInsert' => [
                          ['app\models\Email', 'userRegistration']

    Explanation: in the example we defined that after creating new User model ('afterInsert')
    Email::userRegistration($event) method will be called.
    Since 1.1.0 you may also not define event manager, but just put _events.php
    into your config folder returning the same 'events' array as in example:

    return [
        'app\models\User' => [
            'afterInsert' => [
                ['app\models\Email', 'userRegistration']
    since 1.3.0 handler can also keep additional data and $append boolean as for Event::on() method eg:
    ... [$handlerClassName, $handlerMethodName, ['myData'], false]
You can’t perform that action at this time.