定制 bariew/yii2-event-component 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bariew/yii2-event-component

最新稳定版本:2.0.0-beta

Composer 安装命令:

composer require bariew/yii2-event-component

包简介

Attaches events to all models

README 文档

README

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.

Installation

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.

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:

    <?php
    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]

统计信息

  • 总下载量: 48.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 2
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 5
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-05-23