• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flashdata and refresh

#16
[eluser]Unknown[/eluser]
If I'm reading your post right, you're asking is if there's a way to retrieve data you've set to flashdata without a page reload. This is in fact possible, though I wouldn't recommend it as you're going against the intended functionality of flashdata. You're much better off using an alternative such as passing a variable.

That said, for those of you wondering how to access data from flashdata without a page reload, read on.

If you take a look at the CI Session library, you can see that flashdata is stored the same way as userdata, except with some meta information pre-pended to the flashdata key name. This meta information is used to distinguish 'new' data (data set during the current page load) from 'old' data (data set during a previous page load). On page load, data marked as 'new' is relabeled as 'old', and data previously labeled as 'old' are swept away (unset).

Since flashdata is only supposed to be accessed after a page load, the method that returns flashdata values only looks for data marked with 'old' metadata.

Code:
function flashdata($key)
    {
        $flashdata_key = $this->flashdata_key.':old:'.$key;
        return $this->userdata($flashdata_key);
    }

So if you'd like to access flashdata you've set without reloading the page, the flashdata method won't help you since the new data is still stored as 'new'. However, you can still retrieve the data using the userdata method instead. All that is needed is the correct meta information.

By default, the class variable $this->flashdata_key is set to 'flash'. So flashdata stored like this:

Code:
$this->session->set_flashdata('some_name', 'some_value');

Can be retrieved before the page reload like this:

Code:
$this->session->userdata('flash:new:some_name');

And there you have it, flashdata without a page reload. Again, I wouldn't recommend this for simply passing variable data around, as there are much better solutions available. But if you really must retrieve the data before page reload it is in fact possible.


Messages In This Thread
Flashdata and refresh - by El Forum - 07-09-2010, 10:21 AM
Flashdata and refresh - by El Forum - 07-09-2010, 11:04 AM
Flashdata and refresh - by El Forum - 07-09-2010, 11:36 AM
Flashdata and refresh - by El Forum - 07-09-2010, 12:52 PM
Flashdata and refresh - by El Forum - 07-09-2010, 01:19 PM
Flashdata and refresh - by El Forum - 07-10-2010, 04:15 AM
Flashdata and refresh - by El Forum - 07-10-2010, 09:40 AM
Flashdata and refresh - by El Forum - 07-10-2010, 10:18 AM
Flashdata and refresh - by El Forum - 07-10-2010, 11:22 AM
Flashdata and refresh - by El Forum - 07-10-2010, 12:14 PM
Flashdata and refresh - by El Forum - 07-10-2010, 01:34 PM
Flashdata and refresh - by El Forum - 07-10-2010, 05:33 PM
Flashdata and refresh - by El Forum - 07-11-2010, 12:53 AM
Flashdata and refresh - by El Forum - 07-11-2010, 02:54 AM
Flashdata and refresh - by El Forum - 07-13-2010, 01:06 PM
Flashdata and refresh - by El Forum - 08-02-2010, 01:27 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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