项目作者: ikkez

项目描述 :
Add simple Flash Messages and Flash Keys to PHP Fat-Free Framework
高级语言: PHP
项目地址: git://github.com/ikkez/f3-flash.git
创建时间: 2017-02-17T13:20:31Z
项目社区:https://github.com/ikkez/f3-flash

开源协议:GNU General Public License v3.0

下载


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

Usage

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

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

And to display that in your templates do:

  1. <!-- bootstrap style-->
  2. <F3:repeat group="{{ \Flash::instance()->getMessages() }}" value="{{ @msg }}">
  3. <div class="alert alert-{{ @msg.status }} alert-dismissable">
  4. <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
  5. {{ @msg.text | esc }}
  6. </div>
  7. </F3:repeat>

That’s it.

If you need, you could also add simple keys:

  1. $flash = \Flash::instance()
  2. $f3->set('FLASH', $flash);
  3. $flash->setKey('highlight','bg-success'); // with value
  4. $flash->setKey('show-hint'); // without returns just TRUE
  5. $flash->setKey('error','Catastrophic error occured! ');

for use cases like:

  1. <div class="box {{ @FLASH->getKey('highlight') }}">
  2. <F3:check if="{{ @FLASH->getKey('show-hint') }}">
  3. <p>It's new !!!</p>
  4. </F3:check>
  5. ...
  6. </div>
  1. <F3:check if="{{ @@FLASH && @FLASH->hasKey('error') }}">
  2. <p>{{ @FLASH->getKey('error') }}</p>
  3. </F3:check>

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]