The method of removing the behavior bound to the component in PHP's Yii framework, yii framework
To remove the behavior, you can call the yiibaseComponent::detachBehavior() method to use the behavior-related Joint name implementation:
$component->detachBehavior('myBehavior1');
Copy after login
You can also remove all behaviors:
$component->detachBehaviors();
Copy after login
The above two methods will call yiibaseBehavior::detach(), the code is as follows:
public function detach()
{
// 这得是个名花有主的行为才有解除一说
if ($this->owner) {
// 遍历行为定义的事件,一一解除
foreach ($this->events() as $event => $handler) {
$this->owner->off($event, is_string($handler) ? [$this,
$handler] : $handler);
}
$this->owner = null;
}
}
Copy after login
Contrary to yiibaseBehavior::attach(), the process of unblocking is to do two things: First, set $owner to null , indicating that this behavior is not attached to any class. The second is to release the event handler bound to the class through Component's off(). In a word, start well and end well.
Articles you may be interested in:
- Explanation of the definition and binding methods of behaviors in PHP's Yii framework
- Detailed explanation of how to use Behaviors in PHP's Yii framework
- In-depth explanation of the properties in PHP's Yii framework
- Example tutorials on using database configuration and SQL operations in PHP's Yii framework
- In-depth analysis of PHP's Yii framework event mechanism in
- Comprehensive interpretation of the log function in PHP's Yii framework
- Yii uses find findAll to find out the implementation method of specified fields
- Analyze the addition and deletion check of yii database Change
- Yii PHP Framework practical introductory tutorial (detailed introduction)
- Detailed explanation of attribute injection and method injection of component behavior in PHP's Yii framework
http://www.bkjia.com/PHPjc/1111896.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1111896.htmlTechArticleHow to remove the behavior bound to the component in PHP's Yii framework. To remove the behavior in the yii framework, you can Call the yiibaseComponent::detachBehavior() method to implement it with the name associated with the behavior:...