olund/flash

A small flash module for Anax-MVC

dev-master 2014-05-15 08:06 UTC

This package is not auto-updated.

Last update: 2024-10-26 16:46:53 UTC


README

Scrutinizer Code Quality Build Status Code Coverage You can also find this on Packagist

 _____ _           _
|  ___| | __ _ ___| |__
| |_  | |/ _` / __| '_ \
|  _| | | (_| \__ \ | | |
|_|   |_|\__,_|___/_| |_|

A small PHP Flash module for Anax-MVC based on sessions.

Preview

alt tag

Instructions for Anax-MVC

Add the following to your frontcontroller.

// Start session.
$app->withSession();

// Set flash as a shared service.
$di->setShared('flash', function () {
    $flash = new \Anax\Flash\CFlash();
    return $flash;
});

You can now use Flash

$app->flash->success('Success message');
$app->flash->error('Error message');
$app->flash->notice('Notice message');
$app->flash->warning('Warning message');

To get the html use:

$app->flash->get()

Example:

// Create a route.
$app->router->add('flash', function () use ($app) {
    // Sets the title
    $app->theme->setTitle('Flash');

    // Add some flash messages
    $app->flash->success('This is a success message');
    $app->flash->error('Error message');
    $app->flash->notice('Notice message');
    $app->flash->warning('Warning message');
    $app->flash->success('Success again');

    // Call the flash->get() method.
    $app->views->addString($app->flash->get(), 'main');
    // Use $app->flash->get(false) if you dont have FontAwesome.
});

The output:

<div class='errorMessage'>Error message</div>
<div class='successMessage'>Success message</div>
<div class='noticeMessage'>Notice message</div>
<div class='warningMessage'>Warning message</div>