JellyBool

17773 经验值

public function behaviors() {
        return [
            [
                'class' => BlameableBehavior::className(),
                'createdByAttribute' => 'created_by',
                'updatedByAttribute' => 'updated_by',
            ],
            'timestamp' => [
                'class' => 'yii\behaviors\TimestampBehavior',
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated'],
                ]
            ]
        ];
    }


 public function actionCreate() {
        $model = new Status();
        if ($model->load(Yii::$app->request->post())) {
//            $model->created_by = Yii::$app->user->getId();
//            $model->created_at = time();
//            $model->updated_at = time();
            $save = $model->save();
            if ($save) {
                return $this->redirect(['view', 'id' => $model->id]);
            }
        }
        return $this->render('create', [
                    'model' => $model,
        ]);
    }

报错

Array ( [created_at] => Array ( [0] => Created At不能为空。 ) [updated_at] => Array ( [0] => Updated At不能为空。 ) )
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']

这一行改一下试试?

这个是我改错了 之前是updated_at不行的

感谢博主的分享, 话说你难道就没想过做一个分类么..... 想看一种类型的文章好类啊[囧]

我好想没看见有tag啊, 难道是我眼瞎吗?......