Documentation

FlashMessageService

Flash message service for displaying one-time messages after redirects.

Flash messages are stored in the session and cleared after being retrieved. Supports multiple message types (info, success, warning, error).

Tags
since
3.0.0

Table of Contents

Constants

TYPE_ERROR  = 'error'
TYPE_INFO  = 'info'
Message type constants.
TYPE_SUCCESS  = 'success'
TYPE_WARNING  = 'warning'
KEY_FLASH  = 'flash_messages'
Session key for flash messages.

Methods

add()  : void
Add a flash message.
addMany()  : void
Add multiple messages at once.
clear()  : void
Clear all flash messages without retrieving them.
error()  : void
Add an error message.
getAndClear()  : array<string|int, array{message: string, type: string}>
Get all flash messages and clear them.
getByTypeAndClear()  : array<string|int, array{message: string, type: string}>
Get flash messages by type and clear them.
getCssClass()  : string
Get the Bulma notification CSS class for a message type.
getMessagesAndClear()  : array<string|int, string>
Get only message strings and clear.
has()  : bool
Check if there are any flash messages.
info()  : void
Add an info message.
isError()  : bool
Check if message type indicates an error.
success()  : void
Add a success message.
warning()  : void
Add a warning message.
ensureSession()  : bool
Ensure session is started.

Constants

KEY_FLASH

Session key for flash messages.

private mixed KEY_FLASH = 'flash_messages'

Methods

add()

Add a flash message.

public add(string $message[, string $type = self::TYPE_INFO ]) : void
Parameters
$message : string

Message text

$type : string = self::TYPE_INFO

Message type (info, success, warning, error)

addMany()

Add multiple messages at once.

public addMany(array<string|int, string> $messages[, string $type = self::TYPE_INFO ]) : void
Parameters
$messages : array<string|int, string>

Array of message strings

$type : string = self::TYPE_INFO

Message type for all messages

error()

Add an error message.

public error(string $message) : void
Parameters
$message : string

Message text

getAndClear()

Get all flash messages and clear them.

public getAndClear() : array<string|int, array{message: string, type: string}>
Return values
array<string|int, array{message: string, type: string}>

getByTypeAndClear()

Get flash messages by type and clear them.

public getByTypeAndClear(string $type) : array<string|int, array{message: string, type: string}>
Parameters
$type : string

Message type to retrieve

Tags
psalm-suppress

MixedAssignment

Return values
array<string|int, array{message: string, type: string}>

getCssClass()

Get the Bulma notification CSS class for a message type.

public static getCssClass(string $type) : string
Parameters
$type : string

Message type

Return values
string

Bulma notification class (e.g., 'is-success', 'is-danger')

getMessagesAndClear()

Get only message strings and clear.

public getMessagesAndClear() : array<string|int, string>
Return values
array<string|int, string>

has()

Check if there are any flash messages.

public has([string|null $type = null ]) : bool
Parameters
$type : string|null = null

Optional type filter

Tags
psalm-suppress

MixedAssignment

Return values
bool

info()

Add an info message.

public info(string $message) : void
Parameters
$message : string

Message text

isError()

Check if message type indicates an error.

public static isError(string $type) : bool
Parameters
$type : string

Message type

Return values
bool

success()

Add a success message.

public success(string $message) : void
Parameters
$message : string

Message text

warning()

Add a warning message.

public warning(string $message) : void
Parameters
$message : string

Message text

ensureSession()

Ensure session is started.

private ensureSession() : bool
Return values
bool

True if session is available, false otherwise


        
On this page

Search results