没有命名空间的类 yii yii\base yii\behaviors yii\caching yii\captcha yii\console yii\console\controllers yii\console\widgets yii\data yii\db yii\db\conditions yii\db\cubrid yii\db\cubrid\conditions yii\db\mssql yii\db\mssql\conditions yii\db\mysql yii\db\oci yii\db\oci\conditions yii\db\pgsql yii\db\sqlite yii\db\sqlite\conditions yii\di yii\filters yii\filters\auth yii\grid yii\helpers yii\i18n yii\log yii\mail yii\mutex yii\rbac yii\rest yii\test yii\validators yii\web yii\widgets

Class yii\base\Behavior

继承yii\base\Behavior » yii\base\BaseObject
实现yii\base\Configurable
子类yii\base\ActionFilter, yii\behaviors\AttributeBehavior, yii\behaviors\AttributeTypecastBehavior, yii\behaviors\AttributesBehavior, yii\behaviors\BlameableBehavior, yii\behaviors\CacheableWidgetBehavior, yii\behaviors\OptimisticLockBehavior, yii\behaviors\SluggableBehavior, yii\behaviors\TimestampBehavior, yii\filters\AccessControl, yii\filters\AjaxFilter, yii\filters\ContentNegotiator, yii\filters\Cors, yii\filters\HostControl, yii\filters\HttpCache, yii\filters\PageCache, yii\filters\RateLimiter, yii\filters\VerbFilter, yii\filters\auth\AuthMethod, yii\filters\auth\CompositeAuth, yii\filters\auth\HttpBasicAuth, yii\filters\auth\HttpBearerAuth, yii\filters\auth\HttpHeaderAuth, yii\filters\auth\QueryParamAuth
可用版本自2.0
源码 https://github.com/yiichina/yii2/blob/api/framework/base/Behavior.php

Behavior is the base class for all behavior classes.

A behavior can be used to enhance the functionality of an existing component without modifying its code. In particular, it can "inject" its own methods and properties into the component and make them directly accessible via the component. It can also respond to the events triggered in the component and thus intercept the normal code execution.

For more details and usage information on Behavior, see the guide article on behaviors.

公共属性

隐藏继承的属性

属性类型描述被定义在
$owner yii\base\Component|null The owner of this behavior yii\base\Behavior

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
attach() Attaches the behavior object to the component. yii\base\Behavior
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
detach() Detaches the behavior object from the component. yii\base\Behavior
events() Declares event handlers for the $owner's events. yii\base\Behavior
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject

属性详情

$owner 公共 属性

The owner of this behavior

方法详情

attach() 公共 方法

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.

public void attach($owner)
$owner yii\base\Component

The component that this behavior is to be attached to.

detach() 公共 方法

Detaches the behavior object from the component.

The default implementation will unset the $owner property and detach event handlers declared in events(). Make sure you call the parent implementation if you override this method.

public void detach()
events() 公共 方法

Declares event handlers for the $owner's events.

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:

[
    Model::EVENT_BEFORE_VALIDATE => 'myBeforeValidate',
    Model::EVENT_AFTER_VALIDATE => 'myAfterValidate',
]
public array events()
return array

Events (array keys) and the corresponding event handler methods (array values).