PHP code example of berlioz / flash-bag

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

    

berlioz / flash-bag example snippets


$flashBag = new FlashBag;
$flashBag
    ->add(FlashBag::TYPE_SUCCESS, 'Message success')
    ->add(FlashBag::TYPE_INFO, 'Second message')
    ->add(FlashBag::TYPE_INFO, 'Third message for %d %s', 3, 'persons');

FlashBag::TYPE_INFO = 'info';
FlashBag::TYPE_SUCCESS = 'success';
FlashBag::TYPE_WARNING = 'warning';
FlashBag::TYPE_ERROR = 'error';

$flashBag = new FlashBag;
$successMessages = $flashBag->get('success');

foreach ($successMessages as $msg) {
    print $msg;
}

$flashBag = new FlashBag;
$allMessages = $flashBag->all();

foreach ($allMessages as $type => $messages) {
    foreach ($messages as $msg) {
        print sprintf('%s: %s', $type, $msg);
    }
}