hexbit/php-flash

Its a session based redirector with flash messages for php.

1.0.1 2020-06-04 14:16 UTC

This package is auto-updated.

Last update: 2024-05-05 05:09:20 UTC


README

Its a session based redirector with flash messages for php. you can set flash messages between redirects and you can get your messages only once with php $_SESSION super global array.

Installation

Use the package manager composer to install php flash.

composer require hexbit/php-flash

Usage

use Hexbit\Flash\Flash;

// first initialize it:
Flash::init();


// build a new instance of flash
$flash = new Flash();

// simple usage and redirect back!
$flash->redirectBy('contact')
        ->message('failed', 'It seems your email is not valid!')
        ->redirectBack();

// redirect to specific location
$flash->redirectBy('contact')
        ->redirectLocation("https://somewhere/")
        ->withStatus(302)
        ->message('failed', 'It seems your email is not valid!')
        ->redirect();

// redirect to specific location and then redirect again after 5 seconds!
$flash->redirectLocation("https://somwhere/")
        ->message('failed', 'It seems your email is not valid!')
        ->secondRedirect(5, "https://somewhereelse/")
        ->redirect();

Now your flash messages will be available just once (after redirection) in the superGlobal $_SESSION array.

And obviously, there will be no messages for the next times and will be cleared.

if (isset($_SESSION['failed']) {
        // show your error message for example
}

Contributing

Pull requests are always welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make %sure% to update tests as appropriate.

License

MIT