Session Flash doesn't work with redirect
I'm using Phalcon 1.3.2 with Apache 2.4.4 and PHP 5.4.12 on Win7 x64.
I try to append in my view some flash messages but they don't display.
In services.php
$di->set('flashSess', function() {
return new \Phalcon\Flash\Session(array(
'error' => 'alert alert-danger',
'success' => 'alert alert-success',
'notice' => 'alert alert-warning'
));
});
In my controller
$this->flashSess->error($this->translate->getTranslation()->_("form-app-error"));
$this->response->redirect(array(
'for' => 'dashboardIndex'
));
$this->response->send();
In my view
<?php $this->flashSess->output(); ?>
I also try in my controller
return $this->response->redirect(array(
'for' => 'dashboardIndex'
));
But it doesn't work too.
The only things that work is
return $this->dispatcher->forward(array(
"controller" => "application",
"action" => "index"
));
Is there any risk that when you make a http redirection the view is rendered and flash is outputed anyway? This way the flash message is being outputed but you don't see it - redirection occurs imediately.
When I make a http redirection I always switch the view off.
$this->view->disable();
$this->response->redirect(array(
'for' => 'dashboardIndex'
));
But I may be wrong. Anyway, did it helped?
Hi,
Thanks for the answer, it was a good idea but it doesn't work too :(
How about:
$this->response->redirect('application/index');
I found where did the problem came from. The "dashboardIndex" action use himself a redirection to an other page in some condition with the following snippet :
$this->response->redirect(array(
'for' => 'applicationIndex'
));
$this->response->send();
When i delete the response->send(), it's work ! So don't use response->send() when using flash sessions. Thanks a lot for your answers.