public function actionIndex()
{
if(Yii::$app->session->hasFlash('test')) {
echo 'work';
}
Yii::$app->session->setFlash('test', '1');
return '';
}
public function actionIndex()
{
if(Yii::$app->session->hasFlash('test')) {
echo 'work';
}
Yii::$app->session->setFlash('test', '1');
return '';
}
What do you expect it to do?
Yes, flashes went bad several days ago, it seems that debugging toolbar is behind this. Everything just comes to normal when it is off. When it is enabled, flash survives one request less (I’ve checked session vars). Logging to a file doesn’t matter.
To retrieve a flash one request later. It is possible to set and get it within the same request, but during the next request it seems that it’s not there.
I intended to post an issue, but maybe it would be better to investigate a bit. I’ve traced the problem to this commit. The whole thing looks quite weird. It is possible that it is yii2-debug’s bug, eh?
I’ll check it.
Hmm. I cannot reproduce it with master. I’m trying with default advanced application, /index.php?r=site/request-password-reset.
public function actionIndex()
{
if (Yii::$app->session->hasFlash('test'))
{
echo 'test11';
Yii::warning('test11');
}
Yii::$app->session->setFlash('test', '1', false);
return $this->render('index');
}
It will work as expected in prod environment (with debug toolbar disabled) and won’t work in dev.
Take notice that it certainly will be unreproducible if
return '';
is added, as OP suggested, I wouldn’t bet that it is the same issue as he mentioned.
Reproduced it with fresh advanced. Btw, Yii’s today’s ‘security component’ merge broke it, it won’t work right out of the box without messing with app keys.
It works on dev as well with debug enabled if you’re using latest master code. I’ve just verified that.
I will set up a test rig.
Here,
Debug toolbar is hidden due to ip filter. You need to refresh a couple of times when switching between them.
And zipped web root.
This one is not my usual testing environment, so I’m positive that it not just my local server’s bug.
I set up here Kartik V’s yii2-app-practical-a (it doesn’t have some Advanced’s later commits but it behaved exactly the same as latest Basic or Advanced for me) because of virtual hosting. All the dependencies are recent.
Your test is kinda weird. Try the following:
public function actionFlashSource()
{
Yii::$app->session->setFlash('test', 'hello?');
$this->redirect(['site/flash-destination']);
}
public function actionFlashDestination()
{
return Yii::$app->session->getFlash('test');
}
Thanks, this surely would work, and I find it the most natural scenario for flashes. Yet I have no explanation why the toolbar would consume a flash, and how this all is linked to forementioned commit.