您的位置 首页 技术

Yii 行为是干什么的?

Yii 行为是干什么的? Yii行为是事件的升级版,所有的行为都是Behavior的子类,其作用是将相似事件句柄放在一起,在行为执行“attach()”方法的时候会将“events…

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 行为是干什么的?的详细内容,更多请关注24课堂在线网其它相关文章!

本文来自网络,不代表24小时课堂在线立场,转载请注明出处:https://www.24ketang.cn/72881.html

为您推荐

返回顶部