Answer the question
In order to leave comments, you need to log in
How in Yii2 after adding data to clear the form and display a flash message on the same page without resubmitting?
public function actionAdd()
{
$model = new News();
if ($model->load(Yii::$app->request->post())) {
if ($model->save()) {
Yii::$app->session->setFlash('success', 'Удача: Новость добавлена!');
$model = new News();
} else {
Yii::$app->session->setFlash('error', 'Ошибка: Не удалось добавить новость!');
}
}
return $this->render('add', compact('model'));
}
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