A neat feature which I found in CakePHP was the ability to set a flash
message, say on some save
script, then have that message displayed on the following page. Something like, Post updated
, or Error - no file found.
The way Cake does it is with this session
object. I am trying to avoid sessions like the plague because of their odd requirements for scalability. Can I not just simply store the flash message in a cookie (client side) and then delete that cookie once it's displayed on the following page? What would be some pros/cons to this approach - or more simply, why does Cake uses session
(I'm assuming that relates to the _SESSION
collection).
Cheers!
p.s. In my implementation I also make it fade out with a setTimeout
command in javascript. I find that's a nice way to end the whole process.
The problem with a cookie is that the user may disable this functionality. If so, your flash message won't be showed. CakePHP try to be general enough and uses session storage.
You have 3 options:
In my applications I use a combination of the 2nd and 3rd approaches: I test for cookies and if they are available, I use them. If not, I use database access, BUT I always cache the DB access in order to not query more than once for each message.