EzFlash

Lightweight, simple and easy way to display flash message with Bootstrap 5 (Alert) template

View the Project on GitHub

EzFlash PHP Library

Lightweight, simple and easy way to display flash message with Bootstrap 5 (Alert) template

Usage/Examples

  1. First of all, you can install via composer:
     composer require elmyrockers/ezflash
    
  2. Add the following line into your PHP code:
     require_once 'vendor/autoload.php'; //Load Composer's autoloader
     use elmyrockers\EzFlash;
    
  3. Create new instance of EzFlash class:
     $message = new EzFlash;
    
  4. After that, you can set flash message in 4 different ways:

    $message->{$key} = {$yourmessage};

     $message->success = 'Message'; //Property
     $message['success'] = 'Message'; //Array key
     $message->success( 'Message' ); //Method call or
     $message( 'success', 'Message' ); //Function call
    
  5. Then, that flash message can be displayed using echo:
     echo $message(); //Function call with no parameter
    

    Or you can treat this object like a string:

     echo $message;
    

    For instance, if you write code like the following statement:

     $message( 'success', 'My message' ); //Set flash message through function call
     echo $message; // Echo flash message (one-time display)
    

    Then, its output will look like this one:

     <div class="alert alert-success">My message</div>
    
  6. You can set different template for each $key:
     $message->setTemplate( ['success',
                             'danger',
                             'warning',
                             'info',
                             'primary',
                             'secondary',
                             'light',
                             'dark',
                             'default'], '<div class="alert alert-{$key}">{$message}</div>' ); //default
    
     //custom template
     $message->setTemplate( 'errorInfo', '<div class="alert alert-danger {$key}">{$message}</div>' );
    

    You can override default/existing template too with this.

Reference

Simple Tutorial

Authors

@elmyrockers

License

MIT