Добрый ребят.
При сохранении записи получаю ошибку.
Что не так? Как передать ему ID новой записи?
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'],
];
}