Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
78 lines (69 sloc) 2.14 KB

Flash

The Flash provides multilingual flash notifications.

Installation

composer require webiik/flash

Example

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

Next request:

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

Configuration

setLang

setLang(string $lang): void

setLang() sets current language of flash messages. The default value is en.

$flash->setLang('en');

Adding

addFlashCurrent

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

addFlashCurrent() adds flash message in current language to be displayed in current request. $type represents custom type of message e.g. inf, err, ok. The message may contain {placeholders} which will be replaced with values from the $context array.

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

addFlashNext

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

addFlashNext() adds flash message in current language to be displayed in next request. $type represents custom type of message e.g. inf, err, ok. The message may contain {placeholders} which will be replaced with values from the $context array.

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

Getting

getFlashes

getFlashes(): array

getFlashes() returns array of all messages to be displayed in current request and language.

$flashMessages = $flash->getFlashes();

Resources

You can’t perform that action at this time.