Flash message not showing on redirect

4 years ago

dkorpar
Member | 73
+
0
-

I have problems with showing flashMessage on redirect. it works fine if I don't call
$this->redirect(‘…’);

But with it it does not work.

Here is prnt scr of session data for flashmessages
http://prntscr.com/b2yzb7

Maybe the problem is that in second request (redirect) there are two flash sessions with one being null?
But I just can't find the problem, anybody have some suggestion what could be wrong?
This is template code, and I'm not using nette ajax here…

<div n:snippet="flash" n:ifset="$flashes" class="container-fluid">
    <div class="row" n:foreach="$flashes as $flash">
        <div class="col-md-12 alert alert-{$flash->type} flash-message"
             role="alert">
            <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>{$flash->message}
        </div>
    </div>
</div>

Last edited by dkorpar (2016-05-12 00:45)

4 years ago

GEpic
Member | 569
+
0
-

Maybe n:ifset="$flashes" is problem.

Try to change this condition to n:if="count($flashes) > 0"

Or paste your php code here.

Last edited by GEpic (2016-05-12 01:13)

4 years ago

Aurielle
Member | 1283
+
0
-

It shouldn't be possible to have two flash sessions with different IDs. It may be better to paste your code here. Also, look at your URL – which of those two codes is present? Another problem might lie in the session expiration, if your requests are taking too much time.

4 years ago

dkorpar
Member | 73
+
0
-

Thanks for quick replies, I see that in url theres no query string with _fid option, only things I think it could be wrong is router, I have littlebit complicated router with ?! in presenter I'm not overriding flashMessage
all I have is this:

public function actionLogout()
{
    $this->getUser()->logout();
    $this->flashMessage($this->translator->translate('You have been signed out.'), 'success');
    $this->redirect('Page:Default', 'home');
}

and error is here even if I inherit only Nette\Application\UI\Presenter
this is small part of router code, ofc its not problem in this part, but I'm just thinking could it be connected…

$frontRouter[] = new Route('<lang=en [a-z]{2}>/<path=undefined>', [
    NULL => [
        Route::FILTER_IN => function (array $params) {
            return $this->buildIn($params);
        },
        Route::FILTER_OUT => function (array $params) {
            return $this->buildOut($params);
        }
    ],
], Route::$defaultFlags);

4 years ago

Aurielle
Member | 1283
+
0
-

Your usage of redirect() might be a bit messed up, what are you trying to do there? Apart from that, you don't need to pass Route::$defaultFlags, as it gets passed automatically. I see no other suspicious code.

You can try to take out your specific router and see what happens.

3 years ago

dkorpar
Member | 73
+
0
-

Thanks for answer, why do you think that usage of redirct is messed up?
I see when using different route that doesn't contain filter_in filter_out
(website is on multiple languages and we want all links to be SE friendly so on english is /en/page on German de/seite and so on…)
I'll think I'll by pass broblem with my own router since I'm not sure what's wrong here, all routes are builded up ok and everything works but this…

Last edited by dkorpar (2016-05-23 21:48)

3 years ago

petrknap
Member | 6
+
0
-

I had similar problem as @dkorpar – I had messages in session and they was accessible via my own code, but Nette didn't set them into template.

I fix it in this commit https://github.com/…d02b81e5f806#…