Home  >  Article  >  PHP Framework  >  What does Yii behavior do?

What does Yii behavior do?

Guanhui
GuanhuiOriginal
2020-06-10 15:54:302803browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn