码迷,mamicode.com
首页 > 其他好文 > 详细

yii事件

时间:2016-08-30 00:06:15      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

控制器:

public function actionTests1(){
  $c = new \app\components\cat();
  $m = new \app\components\mou;
  $g = new \app\components\dog;
  Event::on(\app\components\cat::className(),‘miao‘,[$m,‘run‘]);
  // Event::on(cat::className(),‘miao‘,function(){echo 11;});
  // $c->on(‘miao‘,[$m,‘run‘]);
  // $c->on(‘miao‘,[$g,‘look‘]);
  $c->shut();
}

------------------------------

<?php
namespace app\components;
use \yii\base\Event;
class myevent extends Event{
  public $message;
}
class cat extends \yii\base\Component{
  public function shut(){
    echo ‘miaomiaomiao‘;
    $me = new myevent();
    $me->message = ‘sdasdas‘;
    $this->trigger(‘miao‘,$me);
  }
}

-----------------------

<?php
namespace app\components;
class mou{
  public function run($me){
    echo $me->message;
    echo ‘run run run‘;
  }
}

 

yii事件

标签:

原文地址:http://www.cnblogs.com/yifan72/p/5820199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!