控制器:
public function actionTests1(){
$c = new appcomponentscat();
$m = new appcomponentsmou;
$g = new appcomponentsdog;
Event::on(appcomponentscat::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 appcomponents;
use yiiaseEvent;
class myevent extends Event{
public $message;
}
class cat extends yiiaseComponent{
public function shut(){
echo 'miaomiaomiao';
$me = new myevent();
$me->message = 'sdasdas';
$this->trigger('miao',$me);
}
}
-----------------------
<?php
namespace appcomponents;
class mou{
public function run($me){
echo $me->message;
echo 'run run run';
}
}
-----
说明:事件使用场景!在不需要返回值的场景下可使用事件进行处理!