Welcome Guest, Not a member yet? Register   Sign In
Flashdata and refresh
#11

[eluser]mighty_falcon[/eluser]
I am not setting any other cookies, just using the CI sessions.
#12

[eluser]WanWizard[/eluser]
Not using IE and a session cookie that contains an underscore?
#13

[eluser]mighty_falcon[/eluser]
Not sure what you mean, but I have tried multiple browsers (IE, firefox, and chrome) right now using database sessions and it is not working. I know flashdata in other circumstances works okay based on what I have posted...

I also tried it without an underscore and same issue...
#14

[eluser]WanWizard[/eluser]
If it still doesn't work with database sessions, it must be a logic error somewhere.

With the standard CI session class, every call to it immediately updates the session record. Check the database after the page has been loaded, does your session variable exist (you can also use the profiler for that)?
#15

[eluser]mighty_falcon[/eluser]
Ok, so i did a number of tests with the profiler enabled and it still seems that the only way to have the flashdata is by doing a redirect of somekind...

The cart page is where I set the flashdata and it showed up fine in the session table in the DB. Once I click the login link to take me to the login page the redirect variable disappears. If I do a refresh to the login page, instead of a link, the redirect variable is there.

To eliminate any other errors coming from other parts of the code, i removed all other code from the login function and the redirect variable still disappeared.

I guess I will just have have an intermediate step which sets the flashdata and redirects to the login page.
#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.




Theme © iAndrew 2016 - Forum software by © MyBB