How to remove the behavior bound to a component from the Yii framework of PHP

Source: Internet
Author: User
To remove a behavior, call the yiibaseComponent: detachBehavior () method and use the name associated with the behavior: $ component-detachBehavior (myBehavior1). You can also remove all behaviors: $ component-detachBehaviors (); both of the above two methods call yiibaseBehavior: detach ().

To remove a behavior, call the yii \ base \ Component: detachBehavior () method and use the name associated with the behavior: $ component-detachBehavior ('mybehavior1 '); you can also remove all Behavior: $ component-detachBehaviors (); both of the above two methods call yii \ base \ Behavior: detach (), which

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.