Shi*_*da_ 5 yii2 yii2-advanced-app
我想使用GII工具进行CRUD操作,但是Missing required parameters: id当我尝试保存帖子时收到错误消息.
邮政控制器:
public function actionCreate()
{
$model = new Post();
if ($model->load(Yii::$app->request->post())) {
$model->post_create_time=date('Y-m-d h:m:s');
$model->save();
return $this->redirect(['view', 'id' => $model->id_post]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
Run Code Online (Sandbox Code Playgroud)
为什么我总是会收到此错误?
尝试
public function actionCreate()
{
$model = new Post();
if ($model->load(Yii::$app->request->post())) {
$model->post_create_time=date('Y-m-d h:m:s');
$model->save(false);
return $this->redirect(['view', 'id' => $model->id_post]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
Run Code Online (Sandbox Code Playgroud)
确保你这样做$model->save(false),看看它是否有效。