webiik/flash

Flash 提供多语言 flash 通知。

1.0 2019-02-28 21:18 UTC

This package is auto-updated.

Last update: 2024-09-29 05:02:25 UTC


README

Flash

Flash 提供多语言 flash 通知。

安装

composer require webiik/flash

示例

$flash = new \Webiik\Flash\Flash($session);
$flash->addFlashCurrent('inf', 'Hello {name}', ['name' => 'Dolly']);
$flash->addFlashNext('inf', 'Hello {name}', ['name' => 'Molly']);
print_r($flash->getFlashes()); // Array ([inf] => Array ([0] => Hello Dolly ))

下一个请求

$flash = new \Webiik\Flash\Flash($session);
print_r($flash->getFlashes()); // Array ([inf] => Array ([0] => Hello Molly ))

配置

setLang

setLang(string $lang): void

setLang() 设置 flash 消息的当前语言。默认值为 en

$flash->setLang('en');

添加

addFlashCurrent

addFlashCurrent(string $type, string $message, array $context = []): void

addFlashCurrent() 在当前请求中添加当前语言的 flash 消息。 $type 表示消息的自定义类型,例如 inf、err、ok。消息可能包含 {占位符},这些将被 $context 数组中的值替换。

$flash->addFlashCurrent('inf', 'Hello {name}', ['name' => 'Dolly']);

addFlashNext

addFlashNext(string $type, string $message, array $context = []): void

addFlashNext() 在下一个请求中添加当前语言的 flash 消息。 $type 表示消息的自定义类型,例如 inf、err、ok。消息可能包含 {占位符},这些将被 $context 数组中的值替换。

$flash->addFlashNext('inf', 'Hello {name}', ['name' => 'Molly']);

获取

getFlashes

getFlashes(): array

getFlashes() 返回当前请求和语言中要显示的所有消息的数组。

$flashMessages = $flash->getFlashes();

资源