Documentation

CMessage
in package

Manages global static messages.

This class provides a static interface to handle application-wide messages. It supports both non-persistent messages for single (e.g. API) requests and session-based "flash messages" that persist across one page load.

Tags
version
3.0
revision

2

Table of Contents

Properties

$messages  : array<string|int, mixed>

Methods

AddMessage()  : void
Add a message with its relative type.
ClearMessages()  : void
Clear all messages from the session and the current request.
GetMessage()  : array<string|int, mixed>
Get a specific message by its index for the current request.
GetMessages()  : array<string|int, mixed>
Get all messages for the current request.
GetMessagesHave()  : bool
Get a boolean value indicating whether a message of the specified type exists.
GetMessageTexts()  : string
Get a single string containing all messages, each prefixed with its type.
Init()  : void
Initializes the message handler.

Properties

$messages

private static array<string|int, mixed> $messages = []

Contains the list of messages for the current request

Methods

AddMessage()

Add a message with its relative type.

public static AddMessage([string $msg = '' ][, MessageType $type = MessageType::INFO ]) : void

The message is available immediately and, if a session exists, on the next request.

Parameters
$msg : string = ''

text message

$type : MessageType = MessageType::INFO

type of message (::INFO, ::WARNING, ::DANGER, ::PRIMARY, ::SECONDARY)

ClearMessages()

Clear all messages from the session and the current request.

public static ClearMessages() : void

GetMessage()

Get a specific message by its index for the current request.

public static GetMessage(int $n) : array<string|int, mixed>
Parameters
$n : int

The index of the message to retrieve

Return values
array<string|int, mixed> —

The array contains the text and the type of message (['text'=>'...', 'type'=>'info'])

GetMessages()

Get all messages for the current request.

public static GetMessages() : array<string|int, mixed>
Return values
array<string|int, mixed> —

An array of messages, each containing text and type

GetMessagesHave()

Get a boolean value indicating whether a message of the specified type exists.

public static GetMessagesHave(MessageType $type) : bool
Parameters
$type : MessageType

The message type to check for

Return values
bool —

True if at least one message of the specified type exists, false otherwise

GetMessageTexts()

Get a single string containing all messages, each prefixed with its type.

public static GetMessageTexts() : string
Return values
string —

A string containing all formatted messages

Init()

Initializes the message handler.

public static Init() : void

This method should be called once at the beginning of the application's lifecycle. It loads any "flash" messages from the session into the static message list for the current request and then clears them from the session.


        
On this page

Search results