Child classes may override this method to declare what PHP callbacks should
be attached to the events of the [[owner]] component.
The callbacks will be attached to the [[owner]]'s events when the behavior is
attached to the owner; and they will be detached from the events when
the behavior is detached from the component.
The callbacks can be any of the following:
- method in this behavior: 'handleClick', equivalent to [$this, 'handleClick']
- object method: [$object, 'handleClick']
- static method: ['Page', 'handleClick']
- anonymous function: function ($event) { ... }
The following is an example:
php
[
Model::EVENT_BEFORE_VALIDATE => 'myBeforeValidate',
Model::EVENT_AFTER_VALIDATE => 'myAfterValidate',
]
public function events() { $owner = $this->owner; if ($owner instanceof Controller) { return [$owner::EVENT_BEFORE_ACTION => '', $owner::EVENT_AFTER_ACTION => '']; } return parent::events(); }
/** * Declares event handlers for the [[owner]]'s events. * @return array */ public function events() { parent::events(); if (!$this->_hasEventHandlers) { return array_fill_keys($this->events, 'postDeferredEvent'); } else { return array_fill_keys(array_keys($this->events), 'postDeferredEvent'); } }
/** * @inheritDoc */ public function events() { return ArrayHelper::merge(parent::events(), [ActiveRecord::EVENT_AFTER_UPDATE => [$this, 'onAfterUpdate'], ActiveRecord::EVENT_AFTER_FIND => [$this, 'onAfterFind']]); }
/** * Declares events and the corresponding event handler methods. * If you override this method, make sure you merge the parent result to the return value. * @return array events (array keys) and the corresponding event handler methods (array values). * @see CBehavior::events */ public function events() { return array_merge(parent::events(), array(Controller::EVENT_BEFORE_ACTION => 'beforeAction', Controller::EVENT_AFTER_ACTION => 'afterAction')); }
/** * @inheritdoc */ public function events() { return array_merge(parent::events(), [ActiveRecord::EVENT_AFTER_FIND => 'setLanguage']); }
public function events() { $events = parent::events(); $events[\yii\base\Application::EVENT_BEFORE_REQUEST] = 'beforeRequest'; return $events; }
/** * Declares event handlers for the [[owner]]'s events. * @return array */ public function events() { parent::events(); return array_fill_keys(array_keys($this->events), 'routeEvent'); }
/** * @inheritdoc */ public function events() { return array_merge(parent::events(), [BaseActiveRecord::EVENT_BEFORE_VALIDATE => 'resolveSecureAttributesChanged', BaseActiveRecord::EVENT_BEFORE_INSERT => 'resolveConflicts', BaseActiveRecord::EVENT_AFTER_INSERT => 'createSecureItem', BaseActiveRecord::EVENT_AFTER_UPDATE => 'updateSecureItem', BaseActiveRecord::EVENT_AFTER_DELETE => 'deleteSecureItem']); }
/** * @inheritdoc */ public function events() { return array_merge(parent::events(), ['init' => 'afterInit', 'beforeValidate' => 'beforeValidate', 'afterValidate' => 'afterValidate', 'afterFind' => 'afterFind', 'beforeInsert' => 'beforeInsert', 'afterInsert' => 'afterInsert', 'beforeUpdate' => 'beforeUpdate', 'afterUpdate' => 'afterUpdate', 'beforeDelete' => 'beforeDelete', 'afterDelete' => 'afterDelete']); }
/** * Declares events and the corresponding event handler methods. * If you override this method, make sure you merge the parent result to the return value. * @return array events (array keys) and the corresponding event handler methods (array values). * @see CBehavior::events */ public function events() { return array_merge(parent::events(), array('beforeLogin' => 'beforeLogin', 'beforeSignup' => 'beforeSignup', 'beforeRequestPasswordReset' => 'beforeRequestPasswordReset', 'beforeResetPassword' => 'beforeResetPassword', 'beforeLogout' => 'beforeLogout', 'afterRequestPasswordReset' => 'afterRequestPasswordReset', 'afterResetPassword' => 'afterResetPassword', 'afterLogin' => 'afterLogin', 'afterSignup' => 'afterSignup', 'afterLogout' => 'afterLogout', 'errorResetPassword' => 'errorResetPassword', 'errorRequestPasswordReset' => 'errorRequestPasswordReset', 'errorLogin' => 'errorLogin', 'errorSignup' => 'errorSignup')); }