這篇文章主要介紹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)); }
以上是“Yii行為是用來做什么的”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。