Yii 行为是干什么的?

广告:宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取~~~

Yii 行为是干什么的?

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 行为是干什么的?的详细内容,更多请关注9543建站博客其它相关文章!

9543建站博客
一个专注于网站开发、微信开发的技术类纯净博客。
作者头像
admin创始人

肥猫,知名SEO博客站长,14年SEO经验。

上一篇:浅析如何在ThinkPHP中打印SQL错误信息
下一篇:怎么在小程序中引入外部字体

发表评论

关闭广告
关闭广告