ikkez/f3-flash

为PHP Fat-Free Framework添加简单的Flash消息和Flash密钥

1.0.2 2020-12-13 08:43 UTC

This package is auto-updated.

Last update: 2024-09-13 17:14:56 UTC


README

这是一个用于为PHP Fat-Free-Framework版本3.x添加简单Flash消息和Flash密钥的小插件。

安装

  • 方法1:使用composer composer require ikkez/f3-flash

  • 方法2:将flash.php文件复制到您的F3 lib/目录或AUTOLOADER已知的其他目录

使用方法

要在模板中添加只应在下一个请求中显示一次的消息(或多个),只需这样做:

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

然后在您的模板中显示它:

<!-- 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">&times;</button>
  {{ @msg.text | esc }}
</div>
</F3:repeat>

就这样。

如果您需要,也可以添加简单的密钥

$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! ');

用于如下用例:

<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>

许可协议

您可以在GNU通用公共许可证版本3或更高版本下使用此插件。

版权(C)2017 Christian Knuth [ikkez]