Answer the question
In order to leave comments, you need to log in
How does the TimestampBehavior work if the field is already populated?
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'createdAt',
'updatedAtAttribute' => 'updatedAt',
'value' => new Expression('NOW()'),
],
];
}
Answer the question
In order to leave comments, you need to log in
Clear.
The nuts are tightly tightened there - the value specified in behavior is set.
detachBehavior solves the second question
On update , the current timestamp will be stored in updated_at . You can pass your value as a function, or as a string:
[
'class' => TimestampBehavior::className(),
'value' => date('Y.m.d H:i'),
],
[
'class' => TimestampBehavior::className(),
'value' => function($event) {
return date('Y.m.d H:i');
},
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question