PHP code example of romagny13 / flash

1. Go to this page and download the library: Download romagny13/flash 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/ */

    

romagny13 / flash example snippets


$flash = new \MicroPHP\Flash\Flash();
$flash
    ->addMessage('success','<strong>Success!</strong> <i>Message 1</i>')
    ->addSuccess('Success message 2')
    ->addMessage('warning','Warning message 1')
    ->addWarning('Warning message 2')
    ->addMessage('error','Error message 1')
    ->addError('Error message 2')
    ->addMessage('notification','My notification');

$hasSuccessMessages = $flash->hasSuccess();
$hasSuccessMessages = $flash->hasWarning();
$hasSuccessMessages = $flash->hasError();
$hasMessages = $flash->has('notification');

$successMessages = $flash->getSuccessMessages();
$warningMessages = $flash->getWarningMessages();
$errorMessages = $flash->getErrorMessages();
$myMessages = $flash->getMessages('notification');

$successMessage = $flash->getSuccess();
$warningMessage = $flash->getWarning();
$errorMessage = $flash->getError();
$myMessage = $flash->getMessage('notification');



class TwigRenderer
{
    public $twig;

    public function __construct($templateDirectory)
    {
        $loader = new Twig_Loader_Filesystem($templateDirectory);
        $this->twig = new Twig_Environment($loader);
    }

    public function render($viewPath, $params=[]){
        echo $this->twig->render($viewPath,$params);
    }
}

$renderer = new TwigRenderer(__DIR__.'/templates');

$renderer->twig->addGlobal('flash', $flash);

$renderer->render('home.twig');