怪古学院,六安长途汽车站,昌黎黄金海岸天气
要移除行为,可以调用 yii\base\component::detachbehavior() 方法用行为相关联的名字实现:
$component->detachbehavior('mybehavior1');
也可以移除全部行为:
$component->detachbehaviors();
这上面两种方法,都会调用到 yii\base\behavior::detach() ,其代码如下:
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; } }
与 yii\base\behavior::attach() 相反,解除的过程就是干两件事: 一是将 $owner 设置为 null ,表示这个行为没有依附到任何类上。 二是通过component的 off() 将绑定到类上的事件hanlder解除下来。一句话,善始善终。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
YII2框架中使用RBAC对模块,控制器,方法的权限控制及规则的使用示例
YII2框架中ActiveDataProvider与GridView的配合使用操作示例
PhpStorm的使用教程(本地运行PHP+远程开发+快捷键)
网友评论