Yii 行為是干什么的?

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教程》《PHP教程

? 版權聲明
THE END
喜歡就支持一下吧
點贊11 分享