A regular web controller (not REST ).
if ($model->hasErrors()) { Yii::$app->getResponse()->setStatusCode(400); } In the body of action for some reason does not work. Example:
public function actionSave($model, $AJAXvalidate = false) { $post = Yii::$app->request->post(); if ($model->load($post) && $model->save()) { Yii::$app->session->addFlash('success', 'Запись успешно сохранена.'); return $this->redirect(['index']); } else { if (!Yii::$app->request->isPost) { $model->loadDefaultValues(); } if ($model->hasErrors()) { Yii::$app->getResponse()->setStatusCode(400); } return $this->render('form', [ 'model' => $model, ]); } } PS As it turned out, does not work in action games if they are determined through the treit. If you define an action right in the controller, then the code works. Why is that?
$model->hasErrors() == true- Mik