key : a unique id string for a notice
message : a string of text stored for displayed
$notice = new Notice;
$notice->hasFlash(key); // returns true or false
$notice->setFlash('greeting', "Welcome"); // set a notice message
if($notice->hasFlash('greeting'))) {
echo 'Greeting exists';
}
$notice->getFlash(key);
$notice->setFlash('greeting', 'Welcome to our site')
$message = $notice->getFlash('greeting');
var_dump( $message ); // Welcome to our site
$db = (new DB())->openDB(); //open a database class. $db->insert_into('users', ['username' => 'foo']); if( $db->insert() ){ $notice->setFlash('notice', 'message stored successfully'); redirect('display'); }Check flash in display pageif($notice->hasFlash('notice')){ echo $notice->getFlash('notice'); } else { echo redirect('insert'); }
setFlash(), it redirects to
"display" url which displays the last message set. If no message is found,
then a redirection will be made back to the "insert" page.
getFlash() method, flash() returns
the value of an existing or non-existing key without throwing an error.
This means that if a key does not exist, a null value is returned instead.
.
$notice->setFlash('text','1234');
echo $notice->flash('text'); //returns 1234
echo $notice->flash('word'); //returns null
Res only has three static relative methods to access
the notice class. These methods are Res::setFlash() Res::hasFlash() and
Res::flash() which resolves similarly to the corresponding notice class methods.