yii\base\Behavior::attach PHP Метод

attach() публичный Метод

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.
public attach ( Component $owner )
$owner Component 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);
        }
    }

Usage Example

Пример #1
0
 public function attach($owner)
 {
     parent::attach($owner);
     $owner->on(BaseActiveRecord::EVENT_BEFORE_INSERT, [ClearCacheEvent::className(), ClearCacheEvent::EVENT_CLEAR_CACHE]);
     $owner->on(BaseActiveRecord::EVENT_BEFORE_UPDATE, [ClearCacheEvent::className(), ClearCacheEvent::EVENT_CLEAR_CACHE]);
     $owner->on(BaseActiveRecord::EVENT_BEFORE_DELETE, [ClearCacheEvent::className(), ClearCacheEvent::EVENT_CLEAR_CACHE]);
 }
All Usage Examples Of yii\base\Behavior::attach