1
2
3
4
5
6
7
8
9
10
11
12
13
14
public function behaviors()
{
$behaviors = parent::behaviors();
$time = [
'class' => \yii\behaviors\TimestampBehavior::class,
'value' => fn () => date('Y-m-d H:i:s'),
'attributes' => [
\yii\db\ActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'],
\yii\db\ActiveRecord::EVENT_BEFORE_UPDATE => ['update_time'],
],
];
array_push($behaviors, $time);
return $behaviors;
}