2017 © Pedro Peláez
 

library flash

MicroPHP Flash message library

image

romagny13/flash

MicroPHP Flash message library

  • Tuesday, May 2, 2017
  • by romagny13
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Flash

Installation

composer require romagny13/flash

How To run the example

Example with Twig, Bootstrap 3, Animate.css and Toastr, (*1)

composer install
composer start

Go http://localhost:8080/, (*2)

Usage

Example: add messages, (*3)

$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');

Check if has message, (*4)

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

get the messages with, (*5)

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

Get only the first message, (*6)

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

With Twig 1.0

Documentation, (*7)

Note: Twig 2.0 require PHP 7, (*8)

Install Twig, (*9)

composer require twig/twig:~1.0

Render with Twig_Loader_Filesystem, (*10)

<?php

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);
    }
}

Create a renderer with the templates directory path Create a global variable with the flash instance and render the page., (*11)

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

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

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

In the view (a partial for example), (*12)

{% if flash.hasSuccess() %}


{{ flash.getSuccess() }}
{% endif %} {% if flash.has('error') %}
{{ flash.getMessage('error') }}
{% endif %}

Or with multiple messages for example, (*13)

{% if flash.has('success') %}
    {% for message in flash.getMessages('success') %}
        <div class="alert alert-success fadeIn animated">
            {{ message }}
        </div>
    {% endfor %}
{% endif %}

The Versions

02/05 2017

dev-master

9999999-dev

MicroPHP Flash message library

  Sources   Download

MIT

The Development Requires

by Jerome Romagny

micro message flash microphp

02/05 2017

0.0.1

0.0.1.0

MicroPHP Flash message library

  Sources   Download

MIT

The Development Requires

by Jerome Romagny

micro message flash microphp