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 行為是做什麼的?的詳細內容。更多資訊請關注PHP中文網其他相關文章!