The Yii framework of PHP removes the behavior bound to the component.

Source: Internet
Author: User

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.

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.