Answer the question
In order to leave comments, you need to log in
How to set up a notification to appear when a flash message has been set?
I use the kartik/growl widget and one thing is not clear to me, that when I go to any page the widget works, but I need to make the widget work if a flash message is set to it. Let's say in my template views/layout.php
<?= Growl::widget([
'body' => Yii::$app->session->getFlash('update')
]) ?>
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) {
...
$model->validate();
if (!$model->save()) {
print_r($model->getErrors());
} else {
$model->save();
Yii::$app->session->addFlash('update', 'Успешно отредактирован заказ');
return $this->redirect(['view']);
}
}
return $this->render('update', [
'model' => $model,
]);
}
Answer the question
In order to leave comments, you need to log in
if (Yii::$app->session->hasFlash('update')) {
echo Growl::widget([
'body' => Yii::$app->session->getFlash('update')
]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question