Welcome Guest, Not a member yet? Register   Sign In
Setting flashdata
#1

[eluser]ckeller[/eluser]
In previous apps I've built without the CI framework, i would have a $_SESSION['message']['error'] field that was checked by a show_messages() function above forms etc.

However, when attempting to use this:

$this->session->set_flashdata('message_error', 'That is not a valid login combination');

It does show up until the SUBSEQUENT loading of the page. So someone tries to log in, I process that in the controller, and set the flashdata, then show the view, but the message doesn't show up. If I hit refresh (without reposting), it shows up.

Is this really the right behavior? This doesn't make sense to me. The only way it makes sense to me if if it is expected that you redirect back to the form page so that they cannot re-post the form by hitting refresh. However, then I've learned that the validation_errors() function doesn't display any validation errors once you redirect!

It seem like both are slightly off from how they should work. Any thoughts, ideas, suggestions on how to do this better? Thanks.
#2

[eluser]Dam1an[/eluser]
Yes this is expected behavious
Flash data doesn't get instantiated till the next request (in your case on refresh), if you want it to be displayed on this request, just set it as a variable and pass it into the view as per usual
#3

[eluser]ckeller[/eluser]
Makes sense, thanks for the quick response.
#4

[eluser]Zack Kitzmiller[/eluser]
That's always bothered my about flashdata. I understand that it is expected behavior, because it works like POST data, but ugh.

Why not just work like I want.

Lame Sauce is all I can say. Wink
#5

[eluser]Dam1an[/eluser]
[quote author="techneke" date="1249089619"]That's always bothered my about flashdata. I understand that it is expected behavior, because it works like POST data, but ugh.

Why not just work like I want. [/quote]

So you want something to work like you want, even though it's not how you expect? I can see problems if this actually happened Wink




Theme © iAndrew 2016 - Forum software by © MyBB