CodeIgniter Forums
Session Flashdata will not display until 2nd page load - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Session Flashdata will not display until 2nd page load (/showthread.php?tid=40274)



Session Flashdata will not display until 2nd page load - El Forum - 04-04-2011

[eluser]RJ[/eluser]
Hello,

I have users running through a Beta signup sequence. Once the email has been successfully submitted a quick bit of flash data is added and a new view (pending) is loaded (see code below):

Code:
if ( !$send )
{
  $this->session->set_flashdata('message','Doh!  The email did not send.');
  $this->template->build('signup');
}
else
{
  $this->session->set_flashdata('message','Success!  Your validation email has been sent.');
  $this->template->build('pending');
}

The display:
Code:
<h2>Almost done!</h2>
<p>&lt;?php echo $this->session->flashdata('message'); ?&gt;</p>
<h4>Please check your inbox for further instructions.</h4>

The problem is when the system takes you to either of these pages the flashdata does not display UNTIL you refresh the page or go back to the main page. It looks like the template library is not refreshing (or triggering) a refresh for the message to appear (best guess). Any thoughts how to solve?

Thanks


Session Flashdata will not display until 2nd page load - El Forum - 04-04-2011

[eluser]louisl[/eluser]
You need to do this a different way, the flash data is working as intended ie setting as the page processes. That means it can't be read until you go to another page or refresh the one you're on. It's a bit like trying to set a cookie and retrieve it on the same page.

Send your view a variable and check for that instead.


Session Flashdata will not display until 2nd page load - El Forum - 04-04-2011

[eluser]RJ[/eluser]
thanks


Session Flashdata will not display until 2nd page load - El Forum - 04-05-2011

[eluser]n0xie[/eluser]
You can take a look at our message library to get what you want.


Session Flashdata will not display until 2nd page load - El Forum - 04-05-2011

[eluser]RJ[/eluser]
nice thanks


Session Flashdata will not display until 2nd page load - El Forum - 04-05-2011

[eluser]InsiteFX[/eluser]
This is usally cause by page caching!

InsiteFX


Session Flashdata will not display until 2nd page load - El Forum - 04-05-2011

[eluser]Ninjabear[/eluser]
Personally I do a redirect() instead of a view() that way it loads straight away. What's build() though?


Session Flashdata will not display until 2nd page load - El Forum - 04-05-2011

[eluser]InsiteFX[/eluser]
Then redirect like this!
Code:
redirect('where_to', 'refresh');

InsiteFX


Session Flashdata will not display until 2nd page load - El Forum - 04-05-2011

[eluser]William Rufino[/eluser]
yeah, a flashdata will only display on a new page, so you have to redirect!

if you want to display it on the same "request" you are, why don't just use a normal attribute on the class?