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

#1
[eluser]helloworldly[/eluser]
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:
Code:
$this->session->set_flashdata( 'message', 'ERROR: some message here.');

nothing is displayed...

Code:
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!

#2
[eluser]helloworldly[/eluser]
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.

#3
[eluser]dejitaru[/eluser]
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

#4
[eluser]helloworldly[/eluser]
Thanks.

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

Code:
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
Code:
$this->session->set_flashdata('message', 'ERROR: hello world');

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

#5
[eluser]dejitaru[/eluser]
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

#6
[eluser]InsiteFX[/eluser]
If you find that you need to preserve a flashdata variable through an additional request, you can do so using the keep_flashdata() function.

Code:
$this->session->keep_flashdata('item');

InsiteFX

#7
[eluser]helloworldly[/eluser]
Great, thanks for the tip @insitefx I'll check that out. It's much appreciated.

#8
[eluser]helloworldly[/eluser]
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:

http://ellislab.com/forums/viewthread/138823/


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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