CodeIgniter Forums
What is best way to display confirmation messages - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: What is best way to display confirmation messages (/showthread.php?tid=7182)



What is best way to display confirmation messages - El Forum - 03-28-2008

[eluser]welzie[/eluser]
I would like to display confirmation messages to the user after saves, deletes, etc. I haved read through the guide, forum, and wiki, but didn't see any suggested CI solution.

Any suggestions?

P.S. This is my second attempt at posting this, the first attempt failed silently.


What is best way to display confirmation messages - El Forum - 03-28-2008

[eluser]liamstask[/eluser]
Try using the flashdata in the sessions class. It pops a message into the session for just one request.


What is best way to display confirmation messages - El Forum - 03-28-2008

[eluser]MadZad[/eluser]
Concur.

I'll typically have a line like this in my controller:
Code:
$this->data["error_message"] = $this->session->flashdata("error_message");
to get the status message from the session, then pass it to my view:
Code:
if (isset($error_message)) {
    echo '<div class="alert_message">' . $error_message . "</div>\n";
}

In the past, I've run into complications when doing redirects - the flashdata wasn't available. In those cases I used a normal session storage (set_userdata) and then done a read-once fetch (write a function that does the read then unset, for convenience).


What is best way to display confirmation messages - El Forum - 03-28-2008

[eluser]Ebot Ndip-Agbor[/eluser]
take a look at this thread.


What is best way to display confirmation messages - El Forum - 03-29-2008

[eluser]adamp1[/eluser]
Just saved me a lot of work finding that exact post, thanks Ebot. I would also take a look at this thread. Where my class is just a class and a view file his has style sheets and everything. There almost the same.