This method will create the behavior object based on the given
configuration. After that, the behavior object will be attached to
this component by calling the [[Behavior::attach()]] method.
public attachBehavior ( string $name, string | array | |
||
$name | string | the name of the behavior. |
$behavior | string | array | |
the behavior configuration. This can be one of the following: - a [[Behavior]] object - a string specifying the behavior class - an object configuration array that will be passed to [[Yii::createObject()]] to create the behavior object. |
return | the behavior object |
protected function attachSupportBehaviors(Component $owner) { $rangeAttributes = []; foreach ($this->attributes as $attribute => $dbAttribute) { $rangeAttributes[] = $attribute . '_start'; $rangeAttributes[] = $attribute . '_end'; $owner->attachBehavior(0, ['class' => DateTimeRangeBehavior::class, 'startAttribute' => $attribute . '_start_local', 'endAttribute' => $attribute . '_end_local', 'targetAttribute' => $attribute . '_range']); } $owner->attachBehavior(0, ['class' => DateTimeBehavior::class, 'originalFormat' => ['date', 'yyyy-MM-dd'], 'targetFormat' => ['date', 'dd.MM.yyyy'], 'attributes' => $rangeAttributes]); }