Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ikkez/f3-flash

Add simple Flash Messages and Flash Keys to PHP Fat-Free Framework
https://github.com/ikkez/f3-flash

fat-free-framework flash flash-messages

Last synced: 20 days ago
JSON representation

Add simple Flash Messages and Flash Keys to PHP Fat-Free Framework

Awesome Lists containing this project

README

        

# Flash

This is a little plugin to add simple Flash Messages and Flash Keys for PHP Fat-Free-Framework, version 3.x

### Installation

- Method 1: use composer composer require ikkez/f3-flash

- Method 2: copy the `flash.php` file into your F3 `lib/` directory or another directory that is known to the [AUTOLOADER](https://fatfreeframework.com/quick-reference#AUTOLOAD)

### Usage

To add a message (or multiple) that should only be displayed once in your template on the next request, just do:

```php
\Flash::instance()->addMessage('You did that wrong.', 'danger');
// or
\Flash::instance()->addMessage('It worked!', 'success');
```

And to display that in your templates do:

```html


×
{{ @msg.text | esc }}

```

That's it.

If you need, you could also add simple keys:

```php
$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:

```html



It's new !!!



...

```

```html

{{ @FLASH->getKey('error') }}

```

## License

You are allowed to use this plugin under the terms of the GNU General Public License version 3 or later.

Copyright (C) 2017 Christian Knuth [ikkez]