Flash redirects may be corrupted if redirected. I made a simple test code:
public function actionTest($test = 0) { if($test == 0) { Yii::$app->getSession()->addFlash('success', 'Follow the white rabbit'); return Yii::$app->getResponse()->redirect(array('test', 'test' => 1)); } return $this->render('test', []); }
I call an action without a parameter, it adds a flash and redirects. When it displays a page, there is no flash.
The view element is beautiful, because if I install flash and render without redirection, it displays correctly.
Why?
EDIT: Layout view format:
<?php use frontend\widgets\Alert; $this->beginPage(); echo $this->render('partials/head'); ?> <body class="no-sidebar"> <?= $this->beginBody() ?> <div id="header"> <?= $this->render('partials/top') ?> <?= $this->render(Yii::$app->user->isGuest ? 'menus/guest' : 'menus/registered') ?> </div> <!-- Main --> <div id="main"> <?= Alert::widget() ?> <?= $content ?> </div> <?= $this->render('partials/footer') ?> <?= $this->endBody() ?> </body> </html> <?php $this->endPage() ?>
redirect php yii2
Joe
source share