vals2004/yii2-listener

The simple and powerful listener for the Yii2 framework

Installs: 46

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 5

Type:yii2-extension

1.0.2 2015-11-01 20:45 UTC

This package is not auto-updated.

Last update: 2025-01-08 19:12:51 UTC


README

If you want know what events do you have, install this extension and use file "listener" for add some events. You always will know that event you have and that class has assigned

Installation

"repositories": [
    {
        "type": "git",
        "url": "https://github.com/vals2004/yii2-listener.git"
    }  
],

Either run

php composer.phar require --prefer-dist vals2004/yii2-listener "*"

or add

"vals2004/listener": "*"

Config

'bootstrap' => ['eventManager'],
'components' => [
        'eventManager' => [
            'class' => 'vals2004\listener\components\EventManager'
        ],
]

For trigger event use default manual http://www.yiiframework.com/doc-2.0/guide-concept-events.html Global Events or Class-Level Event Handlers(Individual)

Example listener.php

   return [
       //Individual event
       array(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_INSERT) => [
           function ($event) {
               Yii::trace(get_class($event->sender) . ' is inserted');
           },
           ['Yii::$app->myComponent', 'helloWord'],
       ],
       //global event (like namespace)
       'app.controller.actionSignup.success' => [
           function ($event) {
               Yii::trace(get_class($event->sender) . ' is inserted');
           },
           ['Yii::$app->myComponent', 'helloWord'],
       ]
   ]