apeisa Posted February 17, 2012 Share Posted February 17, 2012 It would be great if there would be an easy way to add flash-type of session variables. Here is citation from codeigniter docs: Quote 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"). Link to comment Share on other sites More sharing options...
apeisa Posted February 17, 2012 Author Share Posted February 17, 2012 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!"); Link to comment Share on other sites More sharing options...
Adam Kiss Posted February 18, 2012 Share Posted February 18, 2012 So it's solved? Link to comment Share on other sites More sharing options...
apeisa Posted February 18, 2012 Author Share Posted February 18, 2012 Yep. Although mention about these on session docs and on cheatsheet would be nice. Link to comment Share on other sites More sharing options...
Soma Posted February 18, 2012 Share Posted February 18, 2012 I don't really get it. Notice class has something to do with flash session data? Link to comment Share on other sites More sharing options...
apeisa Posted February 18, 2012 Author Share Posted February 18, 2012 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. 2 Link to comment Share on other sites More sharing options...
ryan Posted February 20, 2012 Share Posted February 20, 2012 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. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now