CodeIgniter Forums
Flashdata and AJAX calls on every page load - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Flashdata and AJAX calls on every page load (/showthread.php?tid=64121)



Flashdata and AJAX calls on every page load - komirad - 01-16-2016

My app has an AJAX request on every page load. (Notifications)

This has made the flashdata feature pretty useless for the rest of the code. As you know flashdata is deleted on the next request, and the ajax call deletes my flashdata.

I have worked around this by looping through all the flashdata and calling keep_flashdata() so that the AJAX request doesn't delete any flashdata.

Is there a better way to handle this?

Maybe a way to say
PHP Code:
if($x){
   
// Set flash data to not delete.


Or should I create my own flashdata library so that I can have different sets of flashdata that can have different configurations? The problem with this is third party libraries will all have to modified.


RE: Flashdata and AJAX calls on every page load - Diederik - 01-17-2016

You can have a look at: https://github.com/jenssegers/codeigniter-message-library

It's very easy to have your own type of flash data that only removes entries when you fetch than and they are used. I have adopted my own version with some added pre formatted output for some fancy bootstrap3 type alert messages.


RE: Flashdata and AJAX calls on every page load - komirad - 01-17-2016

Just had a look at it.

I am using ion_auth which uses flashdata for csrf as seen here: https://github.com/benedmunds/CodeIgniter-Ion-Auth/blob/2/controllers/auth.php $this->session->set_flashdata('csrfkey', $key)

I have to update that controller code to adopt another flashdata like library. And it does look like, I have to do the same with any other library that uses flashdata Sad