hexbit / php-flash
这是一个基于会话的重定向器,用于php,带有闪存消息。
1.0.1
2020-06-04 14:16 UTC
Requires
- php: >=5.6.0
Requires (Dev)
- phpunit/phpunit: ^9.1
This package is auto-updated.
Last update: 2024-09-05 06:03:11 UTC
README
这是一个基于会话的重定向器,用于php,带有闪存消息。您可以在重定向之间设置闪存消息,并且只能通过php $_SESSION
超全局数组获取一次消息。
安装
使用包管理器 composer 安装 php flash。
composer require hexbit/php-flash
用法
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();
现在您的闪存消息将只在超级全局 $_SESSION
数组中一次(在重定向后)可用。
显然,下次将没有消息,并且将被清除。
if (isset($_SESSION['failed']) { // show your error message for example }
贡献
欢迎提交拉取请求。对于重大更改,请首先打开一个问题来讨论您想要更改的内容。
请确保根据适当的情况更新测试。