Home  >  Article  >  Backend Development  >  Yii2 setFlash后redirect后,getFlash总是为空

Yii2 setFlash后redirect后,getFlash总是为空

WBOY
WBOYOriginal
2016-06-06 20:24:421113browse

为啥呢?

<code class="php">Yii::$app->session->setFlash('danger', 'City Wide Curfew');
return Yii::$app->controller->redirect(['/default/index'], 307);</code>

在 /default/index 中 echo Yii::$app->session->getFlash('danger') 总是为空?

回复内容:

为啥呢?

<code class="php">Yii::$app->session->setFlash('danger', 'City Wide Curfew');
return Yii::$app->controller->redirect(['/default/index'], 307);</code>

在 /default/index 中 echo Yii::$app->session->getFlash('danger') 总是为空?

我的解决方法是:在Yii::$app->controller->redirect()后,Yii::$app->end()

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn