PHP 클래스 yii\behaviors\AttributeBehavior

To use AttributeBehavior, configure the [[attributes]] property which should specify the list of attributes that need to be updated and the corresponding events that should trigger the update. Then configure the [[value]] property with a PHP callable whose return value will be used to assign to the current attribute(s). For example, php use yii\behaviors\AttributeBehavior; public function behaviors() { return [ [ 'class' => AttributeBehavior::className(), 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => 'attribute1', ActiveRecord::EVENT_BEFORE_UPDATE => 'attribute2', ], 'value' => function ($event) { return 'some value'; }, ], ]; } Because attribute values will be set automatically by this behavior, they are usually not user input and should therefore not be validated, i.e. they should not appear in the [[\yii\base\Model::rules()|rules()]] method of the model.
부터: 2.0
저자: Luciano Baraglia ([email protected])
저자: Qiang Xue ([email protected])
상속: extends yii\base\Behavior
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$attributes list of attributes that are to be automatically filled with the value specified via [[value]]. The array keys are the ActiveRecord events upon which the attributes are to be updated, and the array values are the corresponding attribute(s) to be updated. You can use a string to represent a single attribute, or an array to represent a list of attributes. For example, php [ ActiveRecord::EVENT_BEFORE_INSERT => ['attribute1', 'attribute2'], ActiveRecord::EVENT_BEFORE_UPDATE => 'attribute2', ]
$skipUpdateOnClean whether to skip this behavior when the $owner has not been modified
$value the value that will be assigned to the current attributes. This can be an anonymous function, callable in array format (e.g. [$this, 'methodName']), an [[\yii\db\Expression|Expression]] object representing a DB expression (e.g. new Expression('NOW()')), scalar, string or an arbitrary value. If the former, the return value of the function will be assigned to the attributes. The signature of the function should be as follows, php function ($event) { return value will be assigned to the attribute }

공개 메소드들

메소드 설명
evaluateAttributes ( Event $event ) Evaluates the attribute value and assigns it to the current attributes.
events ( )

보호된 메소드들

메소드 설명
getValue ( Event $event ) : mixed Returns the value for the current attributes.

메소드 상세

evaluateAttributes() 공개 메소드

Evaluates the attribute value and assigns it to the current attributes.
public evaluateAttributes ( Event $event )
$event yii\base\Event

events() 공개 메소드

public events ( )

getValue() 보호된 메소드

This method is called by AttributeBehavior::evaluateAttributes. Its return value will be assigned to the attributes corresponding to the triggering event.
protected getValue ( Event $event ) : mixed
$event yii\base\Event the event that triggers the current attribute updating.
리턴 mixed the attribute value

프로퍼티 상세

$attributes 공개적으로 프로퍼티

list of attributes that are to be automatically filled with the value specified via [[value]]. The array keys are the ActiveRecord events upon which the attributes are to be updated, and the array values are the corresponding attribute(s) to be updated. You can use a string to represent a single attribute, or an array to represent a list of attributes. For example, php [ ActiveRecord::EVENT_BEFORE_INSERT => ['attribute1', 'attribute2'], ActiveRecord::EVENT_BEFORE_UPDATE => 'attribute2', ]
public $attributes

$skipUpdateOnClean 공개적으로 프로퍼티

whether to skip this behavior when the $owner has not been modified
부터: 2.0.8
public $skipUpdateOnClean

$value 공개적으로 프로퍼티

the value that will be assigned to the current attributes. This can be an anonymous function, callable in array format (e.g. [$this, 'methodName']), an [[\yii\db\Expression|Expression]] object representing a DB expression (e.g. new Expression('NOW()')), scalar, string or an arbitrary value. If the former, the return value of the function will be assigned to the attributes. The signature of the function should be as follows, php function ($event) { return value will be assigned to the attribute }
public $value