Welcome Guest, Not a member yet? Register   Sign In
pass message to new page
#1

[eluser]neofactor[/eluser]
In my traditional PHP apps, after an insert or action I have passed the user to a new page that gave them a message/note telling them the action was completed. The idea was to prevent people clicking refresh causing a re-post of the action.

I typically would send the message back in the URI: page.php?note=Record Inserted

Now in CI... I want to do something similar.

I was curious how you do it. Do I HAVE to enable QueryStrings? I was hoping to avoid that.

I tried this:
Passing back a page/note/Record+Completed but I get the error: "The URI you submitted has disallowed characters."

I was even thinking of encrypting the message and passing it along...


Any thoughts? I would love some seasoned experience on best practices.
#2

[eluser]Dam1an[/eluser]
Flashdata is perfect for this
Read up on it in the session page in the userguide but the general idea is it sets some data in the session which lasts for one page request
#3

[eluser]neofactor[/eluser]
Thanks...

I was trying to do this without luck. Delete login sessions and pass a note.


Code:
function logout()
  {
    $this->session->sess_destroy();
    $this->session->set_flashdata('note', 'Your Session has been Removed');
    redirect('/login/', 'refresh');
  }

even just tried: $this->session->unset_userdata('session_username');

Does flashdata pass on a redirect?
#4

[eluser]neofactor[/eluser]
Disregard that last post... It works wonderfully!
I was not properly printing the response on the page... silly me.

Thanks again for your FAST response.
#5

[eluser]kurucu[/eluser]
I found flashdata a little too short-lived to be useful to me, especially over a redirect. Instead, you could extend the session class (or alternatively write a library etc) and create a session array with information that lives until you next read it, rather than the next page request.

Two simple functions should be easy to write.
#6

[eluser]BrianDHall[/eluser]
More simply, you could just check to see if the certain session variable is set - if it is then echo it out and then unset it. If you use it often you would certainly want to stick it in a function to avoid code duplication, of course - but if it's a one off then no worries.
#7

[eluser]mattthehoople[/eluser]
Why not just load a different "action completed" view?
#8

[eluser]neofactor[/eluser]
I just think it is cleaner to have a status message on the top of the next page... That way I can send any message I need to and not have a bunch of pages dedicated to responses.

The big reason is to prevent the re-post. I guess it just comes down to usability and personal style.

Thanks again for all your feedback... I am good to go now.




Theme © iAndrew 2016 - Forum software by © MyBB