This article mainly introduces how to remove the behavior bound to a component in the PHP Yii Framework. you can use the detachBehavio method or remove all the behaviors. For more information about the behavior to be removed, see, you can call the yii \ base \ Component: detachBehavior () method to use 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.