Flash
This is a little plugin to add simple Flash Messages and Flash Keys for PHP Fat-Free-Framework, version 3.x, (*1)
Installation
-
Method 1: use composer composer require ikkez/f3-flash, (*2)
-
Method 2: copy the flash.php
file into your F3 lib/
directory or another directory that is known to the AUTOLOADER, (*3)
Usage
To add a message (or multiple) that should only be displayed once in your template on the next request, just do:, (*4)
\Flash::instance()->addMessage('You did that wrong.', 'danger');
// or
\Flash::instance()->addMessage('It worked!', 'success');
And to display that in your templates do:, (*5)
<!-- bootstrap style-->
<F3:repeat group="{{ \Flash::instance()->getMessages() }}" value="{{ @msg }}">
<div class="alert alert-{{ @msg.status }} alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{{ @msg.text | esc }}
</div>
</F3:repeat>
That's it., (*6)
If you need, you could also add simple keys:, (*7)
$flash = \Flash::instance()
$f3->set('FLASH', $flash);
$flash->setKey('highlight','bg-success'); // with value
$flash->setKey('show-hint'); // without returns just TRUE
$flash->setKey('error','Catastrophic error occured! ');
for use cases like:, (*8)
<div class="box {{ @FLASH->getKey('highlight') }}">
<F3:check if="{{ @FLASH->getKey('show-hint') }}">
<p>It's new !!!</p>
</F3:check>
...
</div>
<F3:check if="{{ @@FLASH && @FLASH->hasKey('error') }}">
<p>{{ @FLASH->getKey('error') }}</p>
</F3:check>
License
You are allowed to use this plugin under the terms of the GNU General Public License version 3 or later., (*9)
Copyright (C) 2017 Christian Knuth [ikkez], (*10)