PHP code example of plasticbrain / php-flash-messages
1. Go to this page and download the library: Download plasticbrain/php-flash-messages library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
plasticbrain / php-flash-messages example snippets
// Start a Session
if (!session_id()) @session_start();
// Instantiate the class
$msg = new \Plasticbrain\FlashMessages\FlashMessages();
// Add messages
$msg->info('This is an info message');
$msg->success('This is a success message');
$msg->warning('This is a warning message');
$msg->error('This is an error message');
// If you need to check for errors (eg: when validating a form) you can:
if ($msg->hasErrors()) {
// There ARE errors
} else {
// There are NOT any errors
}
// Wherever you want to display the messages simply call:
$msg->display();
$msg->error('This is an error message', 'http://yoursite.com/another-page');
$msg->success('This is a success message');
$msg->success('This is another success message');
$msg->error('This is an error message', 'http://redirect-url.com');
$msg->error("This is a sticky error message (it can't be closed)", null, true);
$msg->warning("This is a sticky warning message (it can't be closed)", null, true);
$msg->success("This is a sticky success message (it can't be closed)", null, true);
$msg->info("This is a sticky info message (it can't be closed)", null, true);
$msg->sticky('This is also a sticky message');
$msg->sticky('This is "success" sticky message', 'http://redirect-url.com', $msg::SUCCESS);
if ($msg->hasErrors()) {
// There are errors, so do something like redirect
}
// Check if there are any INFO messages
if ($msg->hasMessages($msg::INFO)) {
...
}
// Check if there are any SUCCESS messages
if ($msg->hasMessages($msg::SUCCESS)) {
...
}
// Check if there are any WARNING messages
if ($msg->hasMessages($msg::WARNING)) {
...
}
// Check if there are any ERROR messages
if ($msg->hasMessages($msg::ERROR)) {
...
}
// See if there are *any* messages queued at all
if ($msg->hasMessages()) {
...
}