Reputation: 79
Controller:
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['emailto']) && $model->save()) {
\Yii::$app->session->setFlash('success', 'Thanks.');
}
return $this->redirect(Yii::$app->request->referrer);
I have a form in view file, and when I click submit button, page reloads and flash message is displayed, but I don't have any hasFlash or getFlash in view file.
When I add in view file:
<?= Yii::$app->session->getFlash('success') ?>
there are displayed 2 messages. How to delete that one which displays automatically?
Upvotes: 1
Views: 1613
Reputation: 18021
There is third parameter in getFlash()
- set this to true
to automatically delete message that has been displayed.
<?= Yii::$app->session->getFlash('success', null, true) ?>
Upvotes: 2