YII事件EVENT示例

 
模型中
/** * 在初始化时进行事件绑定 */ public function init() { $this->on(self::EVENT_HELLO,[$this,'sendMail']); $this->on(self::EVENT_HELLO,[$this,'notification']); //and so on ... } public function sendMail($event) { echo 'mail sent to admin'; } public function notification($event) { echo 'notification created'; }
控制器中
$obj->trigger(***Model::EVENT_HELLO);//触发所有绑定的事件

 

posted @ 2017-09-21 15:54  雨落知音  阅读(570)  评论(0编辑  收藏  举报