Home > Article > PHP Framework > What does Yii behavior do?
#What does Yii behavior do?
Yii behavior is an upgraded version of events. All behaviors are subclasses of Behavior. Its function is to put similar event handles together. When the behavior executes the "attach()" method, Bind the event handle returned in the "events()" method to achieve the purpose of aspect management and expansion.
Sample code
/** * 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)); }
Recommended tutorial: "PHP Tutorial》《Yii Tutorial》
The above is the detailed content of What does Yii behavior do?. For more information, please follow other related articles on the PHP Chinese website!