Answer the question
In order to leave comments, you need to log in
Why can't save the record?
Kind guys.
I am getting an error while saving the record.
What's wrong? How to pass him the ID of the new record?
SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, , , , , , , null, null, null, null, null).
The SQL being executed was: INSERT INTO "blog" ("id", "name", "title", "title_mobile", "url", "body_start", "body_end") VALUES (NULL, '', '', '', '', '', '') RETURNING "id"
public function actionEdit()
{
$model = new Blog();
$post = Yii::$app->request->post();
$get = Yii::$app->request->get();
$id = Yii::$app->request->get('id');
if ($id) {
$model = Blog::find()->where(['id' => $id])->one();
if (!$model) {
return $this->render('index', [
'name' => 'Ошибка',
'message' => 'Блог не найден',
]);
}
}
if ($model->load(Yii::$app->request->post())) {
$model->save();
$this->redirect(Url::to(['blog/index']));
}
return $this->render('edit', [
'model' => $model,
]);
}
public function rules()
{
return [
[['check_main', 'check_comment', 'check_status', 'id_project', 'type'], 'integer'],
[['name', 'title', 'title_mobile', 'url', 'body_start', 'body_end'], 'string'],
];
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question