Jump to content

Recommended Posts

Posted

It would be great if there would be an easy way to add flash-type of session variables. Here is citation from codeigniter docs:

CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared. These can be very useful, and are typically used for informational or status messages (for example: "record 2 deleted").
Posted

Ahh... now I get it. There is $notices variable. Very nice.

If others are thinking how to use it, just take a look at notices.inc from templates-admin folder. You can access the very same $notices from your template code. And setting these notices is super simple:

$session->error("Houston, we have a problem");
$session->message("Hello world!");
Posted

You do this on template:

$session->error("error error");

or this on class:

$this->session->error("error error");

End then on next page load you can have this:

foreach($notices as $notice) {
if($notice instanceof NoticeError) {
 echo "<p>$notice->text</p>";
}
}

And that error notice is gone, no need to clear it yourself.

  • Like 2
Posted

I never knew the name for it. It's good to hear that, "flashdata". :) This was mainly setup so that modules could queue messages that would only be seen on a follow-up page. Since many modules do a session->redirect() after a save, there needed to be a way to queue those messages to be seen on the following page load rather than the current (where they would never be seen). I don't think that you actually have to call $session->message(), as I think any notice sent through message() or error() gets queued. Though calling $session->message() is a good way to make that intention clear from the code side.

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...