Rails flash in php

A friend told me about Rail's flash concept which makes it very easy to provide "success" messages and such after submitting a form.

This is some quick code that does something like that (assuming you have a session running) in PHP: (really just a test of posting code)

/**
* This class lets you set variables that are kept for 1 session pageload, then destroyed (hence the "Flash"), which on the next pageload get reflected in a template (for example).
* For use with submitting forms and returning an error message, for example.
*/
class sessionFlashBucket
{
/**
* write a new variable to FlashBucket with a value
*/
function write($var, $val)
{
// put this var in the users _SESSION
$_SESSION[$var] = $val;
return TRUE;
}
/**
* read and empty variable from FlashBucket ('message' by default)
*/
function read($var = "message")
{
// get variable from session
$result = $_SESSION[$var];

// delete variable from FlashBucket
unset($_SESSION[$var]);
return $result;
}
}

# Apr 22, 2007