A
A
akula222016-04-11 09:36:51
Yii
akula22, 2016-04-11 09:36:51

How to see where the error is when adding an entry in yii2?

Classic controller

public function actionCreate()
    {
        $model = new Post;

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

when adding an entry, I remain on the same page, i.e. the model is not saved, and no errors are displayed. How to correctly make validation errors or what else could be displayed on the screen?
I understand that there is $model->getErrors() but why is it not written in the controller by default?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2016-04-11
@akula22

It also should not be registered in the controler. Try adding yii2x.com/display-form-errors-errorsummary <?= $form->errorSummary($model)
right after creating the form . ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question