0

At the end of my controller I have this code:

print_r($this->session->all_userdata());
$this->load->view('common/site_header');

On the first line of my site_header file I have:

print_r($this->session->all_userdata());

The first print_r contains;

[flash:new:error] => Formulier niet correct ingevuld.

The print_r in the site_header file does not contain this entry, after I resubmit the form the second print_r contains:

[flash:old:error] => Formulier niet correct ingevuld.

It looks to me as if the view has a different session object and is one request behind or something.

How do I get the flashdata in the view in the same request?

jleft
  • 3,457
  • 1
  • 23
  • 35
FlyingNimbus
  • 453
  • 2
  • 5
  • 11
  • The session object is globally available in CI. There is only one instance of it, so your controllers and views share it. To me it looks like you're resetting your flashdata before the view is shown. Have you defined any hooks that reset flashdata? – thpl May 15 '13 at 11:50
  • Can you try $this->session->keep_flashdata(var) before the views? Alos, do you set the flashdata in your model or controller? – karmafunk May 15 '13 at 11:53
  • I set the flashdata directly above the print_r in my controller. I also have confirmed that the session constructor is called twice in this one request. I have the session in the autoload, and I dont have any hooks, and as you can see I dont have any code between the first print_r and the print_r in the view file – FlyingNimbus May 15 '13 at 12:07
  • Flashdata is only available for the next server request. Loading a view isn't a server request, you could use a redirect (which is a server request) to a function that loads the appropriate views. [Hopefully my previous answer here](http://stackoverflow.com/a/12105084/604532) might help? – jleft May 15 '13 at 12:57

1 Answers1

1

flash data is available only for the next request, use $this->session->userdata(); instead

itsme
  • 48,972
  • 96
  • 224
  • 345
  • I had a wrong understanding of how to use flashdata, thank you – FlyingNimbus May 15 '13 at 13:09
  • 1
    Flashdata is only available for the next server request, not the second. If you want to preserve it for an additional request, you need to use `$this->session->keep_flashdata('item');` – jleft May 15 '13 at 13:24