H
H
hollanditkzn2017-07-26 11:27:10
Yii
hollanditkzn, 2017-07-26 11:27:10

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')
        ]) ?>

In the controller
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,
        ]);
    }

But as I announced that I have growl It
always appears, no matter what page I click, it always appears

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-07-26
@hollanditkzn

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 question

Ask a Question

731 491 924 answers to any question