Exemple #1
0
 /**
  * Attaches the behavior object to the component.
  * The default implementation will set the [[owner]] property
  * and attach event handlers as declared in [[events]].
  * Make sure you call the parent implementation if you override this method.
  * @param Component $owner the component that this behavior is to be attached to.
  */
 public function attach($owner)
 {
     $this->owner = $owner;
     foreach ($this->events() as $event => $handler) {
         $owner->on($event, is_string($handler) ? [$this, $handler] : $handler);
     }
 }
Exemple #2
0
 /**
  * Attaches the behavior object to the component.
  * The default implementation will set the [[owner]] property
  * and attach event handlers as declared in [[events]].
  * Make sure you call the parent implementation if you override this method.
  * @param Component $owner the component that this behavior is to be attached to.
  */
 public function attach($owner)
 {
     $this->owner = $owner;
     // 设置好行为的$owner, 使得行为可以访问,操作所依附的对象
     foreach ($this->events() as $event => $handler) {
         // 遍历行为中得events()返回的数组,将准备响应的事件,通过所依附类的on()绑定到类上
         $owner->on($event, is_string($handler) ? [$this, $handler] : $handler);
     }
 }