The Yii framework of PHP removes the behavior bound to the component.
To remove a behavior, you can call the yii \ base \ Component: detachBehavior () method to implement it with the name associated with the behavior:
$component->detachBehavior('myBehavior1');
You can also remove all actions:
$component->detachBehaviors();
The preceding two methods call yii \ base \ Behavior: detach (). The Code is as follows:
Public function detach () {// this must be an action with a Master name. Only when the if ($ this-> owner) {// traverses the event defined by the behavior, revoke foreach ($ this-> events () as $ event =>$ handler) {$ this-> owner-> off ($ event, is_string ($ handler )? [$ This, $ handler]: $ handler) ;}$ this-> owner = null ;}}
Unlike yii \ base \ Behavior: attach (), the process of Unbinding is to do two things: first, set $ owner to null, indicating that this Behavior is not attached to any class. The second is to remove the event hanlder bound to the class through the off () of Component. In a word, beginning and end.
Articles you may be interested in:
- Definition and binding of behavior in PHP Yii framework
- Detailed description of Behaviors in PHP Yii framework
- In-depth explanation of attributes in PHP Yii framework)
- Tutorial on using database configuration and SQL operations in PHP Yii framework
- In-depth analysis of event mechanism in PHP Yii framework
- A comprehensive explanation of the log function in the PHP Yii framework
- Yii Use find findAll to find the implementation of the specified field
- Parsing the addition, deletion, query, and modification of the yii Database
- Yii PHP Framework practical getting started tutorial (details)
- Describes the property injection and method injection of component behavior in the Yii framework of PHP.