mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-25 03:01:21 +08:00
Fixes #4571: ignore non-string attribute names for AttributeBehavior.
This commit is contained in:
@@ -93,7 +93,10 @@ class AttributeBehavior extends Behavior
|
|||||||
$attributes = (array) $this->attributes[$event->name];
|
$attributes = (array) $this->attributes[$event->name];
|
||||||
$value = $this->getValue($event);
|
$value = $this->getValue($event);
|
||||||
foreach ($attributes as $attribute) {
|
foreach ($attributes as $attribute) {
|
||||||
$this->owner->$attribute = $value;
|
// ignore attribute names which are not string (e.g. when set by TimestampBehavior::updatedAtAttribute)
|
||||||
|
if (is_string($attribute)) {
|
||||||
|
$this->owner->$attribute = $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,10 +54,12 @@ class BlameableBehavior extends AttributeBehavior
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string the attribute that will receive current user ID value
|
* @var string the attribute that will receive current user ID value
|
||||||
|
* Set this property to be null if you do not want to record the creator ID.
|
||||||
*/
|
*/
|
||||||
public $createdByAttribute = 'created_by';
|
public $createdByAttribute = 'created_by';
|
||||||
/**
|
/**
|
||||||
* @var string the attribute that will receive current user ID value
|
* @var string the attribute that will receive current user ID value
|
||||||
|
* Set this property to be null if you do not want to record the updater ID.
|
||||||
*/
|
*/
|
||||||
public $updatedByAttribute = 'updated_by';
|
public $updatedByAttribute = 'updated_by';
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -64,10 +64,12 @@ class TimestampBehavior extends AttributeBehavior
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string the attribute that will receive timestamp value
|
* @var string the attribute that will receive timestamp value
|
||||||
|
* Set this property to be null if you do not want to record the creation time.
|
||||||
*/
|
*/
|
||||||
public $createdAtAttribute = 'created_at';
|
public $createdAtAttribute = 'created_at';
|
||||||
/**
|
/**
|
||||||
* @var string the attribute that will receive timestamp value
|
* @var string the attribute that will receive timestamp value.
|
||||||
|
* Set this property to be null if you do not want to record the update time.
|
||||||
*/
|
*/
|
||||||
public $updatedAtAttribute = 'updated_at';
|
public $updatedAtAttribute = 'updated_at';
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user