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?

4
  • 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? Commented May 15, 2013 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? Commented May 15, 2013 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 Commented May 15, 2013 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 might help? Commented May 15, 2013 at 12:57

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I had a wrong understanding of how to use flashdata, thank you
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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.