• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get session->flashdata() working in HMVC module?

My app = CI + Modular Extensions - HMVC.

+ 'Session' library is autoloaded.
+ Am able to store and retrieve session flash data from application/somecontroller
+ BUT I am unable to store and retrieve session flash data from Modular Extension controller that is loaded into application/someview via ajax.

Adding this to module's controller does not seem to store the data:
$this->session->set_flashdata( 'message', 'ERROR: some message here.');

nothing is displayed...

echo $this->session->flashdata('message');

... unless I set flashdata within the parent application/somecontroller.

Thoughts how to make this work via the module so that I can provide error / notice messaging within a module? Thanks!

Hope I categorized this thread properly - not sure if it should be here or the ignited code discussion... or even the Wiki Discussions forum since the Modular Extension HMVC is posted to the Wiki there.

Anyone out there come across issues with session flash data when working with Modular Extension hmvc?

Thanks much.

Maybe if you post some code, because I'm using flashvars using the modlse extension and I have no problems at all, even using ajaxcalls


A test in application/modules/module-name/controllers/module-name.php:

function function-name()
$this->session->set_flashdata('message', 'ERROR: hello world');
echo 'flash message = ' . $this->session->flashdata('message');

Which only works if the parent controller that loads this module (via ajax) has
$this->session->set_flashdata('message', 'ERROR: hello world');

otherwise 'message' is empty as it was never set it seems...

Well, the problem is that you forgot to read something in the CI user guide:

"CodeIgniter supports 'flashdata', or session data that will only be available for the next server request, and are then automatically cleared. "

The flashvar only exists until the next server call, thats the reason when you user your ajax call it works and within your function doesnt

If you find that you need to preserve a flashdata variable through an additional request, you can do so using the keep_flashdata() function.



Great, thanks for the tip @insitefx I'll check that out. It's much appreciated.

By the way, could CI's updating of session IDs be related to problem?

"The CI Session library automatically updates the session information i.e changes the session_id (by default) every 5 mins. While this is a very useful security feature to thwart session hijacking, it can prove to be a bone when using AJAX." more info:


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.