Yii 行为是干什么的?
Yii行为是事件的升级版,所有的行为都是Behavior的子类,其作用是将相似事件句柄放在一起,在行为执行“attach()”方法的时候会将“events()”方法中返回的事件句柄进行绑定,这样做达到方面管理和扩展的目的。
示例代码
/** * Raised right BEFORE the application processes the request. * @param CEvent $event the event parameter */ public function onBeginRequest($event) { $this->raiseEvent('onBeginRequest',$event); } /** * Runs the application. * This method loads static application components. Derived classes usually overrides this * method to do more application-specific tasks. * Remember to call the parent implementation so that static application components are loaded. */ public function run() { if($this->hasEventHandler('onBeginRequest')) $this->onBeginRequest(new CEvent($this)); $this->processRequest(); if($this->hasEventHandler('onEndRequest')) $this->onEndRequest(new CEvent($this)); }
推荐教程:《PHP教程》《Yii教程》
以上就是Yii 行为是干什么的?的详细内容,
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)