Flash messages disappear after redirect

5 years ago

temistokles
Member | 7
+
0
-

After redirecting my flashes disapper. The _fid parameter stays present, the session physically contains the data but nothing gets passed to the template.

It fails e.g. while processing signal (but any redirect is a show stopper):

public function handleToggleVisible($id) {
   ...
   $this->flashMessage('...');
   $this->redirect('this');
}

When not redirecting, the messages display correctly. They are placed in separate snippet which gets invalidated when using Ajax (in this case the messages also get displayed correctly).

I have spent several hours trying to get over the problem, it persists in Nette 2.1 as well as 2.0.10, therefore problem is either present in the whole branch or at my side :).

Any help appreciated.

5 years ago

temistokles
Member | 7
+
0
-

This seem to do the trick:

public function beforeRender() {
    ...
    if (isset($this->params[self::FLASH_KEY])) {
        $this->template->flashes = $this->getFlashSession()->flash;
    }
    ...
}

But obviosly this should have been done automatically. In my case it is not.

Last edited by temistokles (2014-03-10 16:17)

5 years ago

Jan Tvrdík
Nette guru | 2553
+
0
-

How do you create template instance? Do you use default createTemplate() implementation?

5 years ago

temistokles
Member | 7
+
0
-

I use:

public function createTemplate($class = NULL) {
    $template = parent::createTemplate($class);
    $template->setTranslator($this->translator);

    return $template;
}