0
votes

I want to $this->Session->setFlash('text'); $this->redirect('page'); but the message is not displayed. I have included both the Session Component and Helper, and the $this->Session->setFlash() in my layout. However, after the redirect, the session doesn't contain any message. If I don't redirect, the message is shown.

So my question is, why isn't the flash message preserved after a redirect? It should be, and this how I've done before, but...it doesn't work now.

Thanks for any help!

Here is my controller code:

if(!$this->Test->__test_possible()){
        $this->Session->setFlash(__('Insufficient data to create test.', true));
        $this->redirect(array('action' => 'index'));
    }

...my layout...(the cake default.ctp)

<?php echo $this->Session->flash(); ?>

and the AppController:

var $helpers = array('Html', 'Form', 'Session', 'Facebook.Facebook');
var $components = array('Session', 'Auth', 'Facebook.Connect');
3
have you tested on other servers? - Headshota
I'm currently testing on my localhost and don't have the possibility to test on other servers. But it is annoying, it has been working before! What could have happened? - linkyndy
and please post some code of your layout and controller. - Headshota
I've edited my question, thank you! - linkyndy
hm, code seems to be correct. maybe facebook component is causing some session conflict? try to unload it temporarily. - Headshota

3 Answers

3
votes

So we just chased down an odd issue where flash messages would not be displayed, despite having all the proper code. It turned out there was a space character after the closing ?> in the controller file. ಠ_ಠ

1
votes

Oh darn...I've put Configure::write('Session.cookie', 'Capitalize.me'); in the core.php and it seems he didn't like the dot in the name...now everything works fine. It's frustrating, really. Thanks for your help :)

0
votes

Flash messages are shown once and then deleted from the cache. You're probably printing it before the redirect, which causes it to not show up on the redirect.