我的行为在我的模型定制Yii2 TimestampBehavior
public function behaviors()
{
return [
[
'class' => SluggableBehavior::className(),
'attribute' => 'title',
// 'slugAttribute' => 'slug',
],
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => time(),
],
];
}
一切工作。但我只需要在一个行动中不起作用。 在actionView中没有必要改变“update_at”属性。我的动作查看:
$model = $this->findModel($id);
$model->views++;
$model->save();
我该如何做到尽可能正确?
在db“updated_at”不会改变。但是在视图(渲染)中仍然在改变属性“update_at”。 – Vitaxxxa
'$ model-> refresh()'保存后 – Yupik
是的,它的工作,tnx – Vitaxxxa