Jump to content


Flashdata

solved session

  • Please log in to reply
6 replies to this topic

#1 apeisa

apeisa

    Hero Member

  • Moderators
  • 1,420 posts
  • 94

  • LocationHelsinki, Finland

Posted 17 February 2012 - 04:17 PM

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").

Follow me at Twitter - Mostly about ProcessWire    AdminBar - Simple front end editing for PW    ProcessRedirects - Manage redirects in PW-admin

#2 apeisa

apeisa

    Hero Member

  • Moderators
  • 1,420 posts
  • 94

  • LocationHelsinki, Finland

Posted 17 February 2012 - 04:58 PM

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!");

Follow me at Twitter - Mostly about ProcessWire    AdminBar - Simple front end editing for PW    ProcessRedirects - Manage redirects in PW-admin

#3 adamkiss

adamkiss

    Hero Member

  • Moderators
  • 662 posts
  • 20

Posted 18 February 2012 - 09:11 AM

So it's solved? :)
If your problem isn't solved by using search function (wink, wink), please don't hesitate to ask.

I like content PW user more than confused not-PW users :)

#4 apeisa

apeisa

    Hero Member

  • Moderators
  • 1,420 posts
  • 94

  • LocationHelsinki, Finland

Posted 18 February 2012 - 09:14 AM

Yep. Although mention about these on session docs and on cheatsheet would be nice.
Follow me at Twitter - Mostly about ProcessWire    AdminBar - Simple front end editing for PW    ProcessRedirects - Manage redirects in PW-admin

#5 Soma

Soma

    Hero Member

  • Moderators
  • 1,051 posts
  • 108

  • LocationSH, Switzerland

Posted 18 February 2012 - 10:36 AM

I don't really get it. Notice class has something to do with flash session data?
@somartist - wire("soma")->is("creative|coder")->say("hello");

#6 apeisa

apeisa

    Hero Member

  • Moderators
  • 1,420 posts
  • 94

  • LocationHelsinki, Finland

Posted 18 February 2012 - 12:01 PM

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.
Follow me at Twitter - Mostly about ProcessWire    AdminBar - Simple front end editing for PW    ProcessRedirects - Manage redirects in PW-admin

#7 ryan

ryan

    Hero Member

  • Administrators
  • 2,882 posts
  • 236

  • LocationAtlanta, GA

Posted 20 February 2012 - 01:39 PM

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

ServInt
Web hosting by ServInt