1 /basic/controllers/TestController.php 添加方法
public function actionTest(){
$person = new Person();
$this->on('SayHello', [$person,'say_hello'],'你好,朋友 hello');
$this->on('SayGoodBye', ['app\models\Person','say_goodbye'],'再见了');
$this->on('GoodNight', function(){
echo '晚安!';
});
$this->trigger('SayHello');
$this->trigger('SayGoodBye');
$this->trigger('GoodNight');
}
2 /basic/models 添加Person.php
<?php
namespace app\models;
use yii\base\Model;
class Person extends Model{
public function say_hello($parm){
echo $parm->data;
}
public function say_goodbye($parm){
echo $parm->data;
}
}