PHPackages                             bariew/yii2-event-component - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bariew/yii2-event-component

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

bariew/yii2-event-component
===========================

Attaches events to all models

1.2.1(11y ago)2149.2k↓45.5%2BSD-3-ClausePHP

Since May 28Pushed 11y ago5 watchersCompare

[ Source](https://github.com/bariew/yii2-event-component)[ Packagist](https://packagist.org/packages/bariew/yii2-event-component)[ RSS](/packages/bariew-yii2-event-component/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (9)Used By (0)

Yii2 event manager component
============================

[](#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' =&gt; \[ 'eventName' =&gt; \[ 'event\\handler\\ClassName' =&gt; 'methodName' \] \] \];

See example below.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

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.

Usage
-----

[](#usage)

```
    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:
