在yii2中更新时,创建时间无效

在yii2中更新时,创建时间无效,yii2,Yii2,当我想在yii2中更新表单时 它告诉我这个错误 创建时间无效--更新时间无效 你认为是什么 public function beforeSave($insert) { $date = new \DateTime(); $date->setTimestamp(time()); $date->setTimezone(new \DateTimezone('Istanbul')); $this->update_time = $date->forma

当我想在yii2中更新表单时

它告诉我这个错误

创建时间无效--更新时间无效

你认为是什么

public function beforeSave($insert)
{
    $date = new \DateTime();
    $date->setTimestamp(time());
    $date->setTimezone(new \DateTimezone('Istanbul'));
    $this->update_time = $date->format('Y-m-d H:i:s');
    if($this->isNewRecord)
        $this->creation_time = $date->format('Y-m-d H:i:s');
    return parent::beforeSave($insert);
}
我的问题已经解决了

在规则中将日期更改为“安全”

   [['creation_time', 'update_time'], 'safe'],

只是可以使用可用的行为

从模型中删除这两个属性的所有验证规则
creation\u time
update\u time

您的代码是正确的“良知”,但有时赋值不起作用,所以只需删除该值或使用该值即可

public function behaviors()
{
    return [
        [
            'class' => TimestampBehavior::className(),
            'createdAtAttribute' => 'create_time',
            'updatedAtAttribute' => 'update_time',
            //'value' => new Expression('NOW()'),
        ],
    ];
}
只需评论一下价值, 它会起作用的。
有关详细信息,请显示确切的错误消息。。错误来自异常?表格a验证规则。。。从表单validation发送错误,然后更新您的问题并添加此模型的验证规则
public function behaviors()
{
    return [
        [
            'class' => TimestampBehavior::className(),
            'createdAtAttribute' => 'create_time',
            'updatedAtAttribute' => 'update_time',
            //'value' => new Expression('NOW()'),
        ],
    ];
}