---
title: "Phalcon Flash"
version: "5.20"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.phalcon.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Phalcon Flash

:::info[NOTE]
All classes are prefixed with `Phalcon`
:::

## Flash\AbstractFlash

Abstract

Shows HTML notifications related to different circumstances. Classes can be
stylized using CSS

```php
$flash->success("The record was successfully deleted");
$flash->error("Cannot open the file");
```

- `\stdClass`
- [`Phalcon\Di\AbstractInjectionAware`](/5.20/api/phalcon_di/#diabstractinjectionaware)
- **`Phalcon\Flash\AbstractFlash`** - implements [`Phalcon\Flash\FlashInterface`](#flashflashinterface)
- [`Phalcon\Flash\Direct`](#flashdirect)
- [`Phalcon\Flash\Session`](#flashsession)

`Phalcon\Contracts\Flash\FlashTypes` · `Phalcon\Di\AbstractInjectionAware` · `Phalcon\Di\Di` · `Phalcon\Di\DiInterface` · `Phalcon\Flash\Exceptions\EscaperServiceUnavailable` · `Phalcon\Flash\Exceptions\FlashMessageNotStringOrArray` · `Phalcon\Html\Escaper\EscaperInterface` · `Phalcon\Session\ManagerInterface` · `Phalcon\Traits\Support\Helper\Str\InterpolateTrait`

### Method Summary

<ApiItem href="#flashabstractflash-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"EscaperInterface|null","name":"escaper","default":"null"},{"type":"SessionInterface|null","name":"session","default":"null"}]}>
AbstractFlash constructor.
</ApiItem>
<ApiItem href="#flashabstractflash-clear" visibility="public" name="clear" returnType="void" params={[]}>
Clears accumulated messages when implicit flush is disabled
</ApiItem>
<ApiItem href="#flashabstractflash-error" visibility="public" name="error" returnType="string|null" params={[{"type":"string","name":"message","default":null}]}>
Shows a HTML error message
</ApiItem>
<ApiItem href="#flashabstractflash-getautoescape" visibility="public" name="getAutoescape" returnType="bool" params={[]}>
Returns the flag that defines whether to automatically escape content or not
</ApiItem>
<ApiItem href="#flashabstractflash-getautomatichtml" visibility="public" name="getAutomaticHtml" returnType="bool" params={[]}>
Returns the flag that defines whether to automatically use HTML or not
</ApiItem>
<ApiItem href="#flashabstractflash-getcssclasses" visibility="public" name="getCssClasses" returnType="array" params={[]}>
Returns the array of the CSS classes for formatting messages. The key is
</ApiItem>
<ApiItem href="#flashabstractflash-getcssiconclasses" visibility="public" name="getCssIconClasses" returnType="array" params={[]}>
Returns the array of the icon CSS classes for formatting messages. The
</ApiItem>
<ApiItem href="#flashabstractflash-getcustomtemplate" visibility="public" name="getCustomTemplate" returnType="string" params={[]}>
Returns the custom template for formatting messages
</ApiItem>
<ApiItem href="#flashabstractflash-getescaperservice" visibility="public" name="getEscaperService" returnType="EscaperInterface" params={[]}>
Returns the Escaper Service
</ApiItem>
<ApiItem href="#flashabstractflash-message" visibility="public" name="message" returnType="string|null" params={[{"type":"string","name":"type","default":null},{"type":"mixed","name":"message","default":null}]}>
Outputs a message. Delivery semantics differ per implementation:
</ApiItem>
<ApiItem href="#flashabstractflash-notice" visibility="public" name="notice" returnType="string|null" params={[{"type":"string","name":"message","default":null}]}>
Shows a HTML notice/information message
</ApiItem>
<ApiItem href="#flashabstractflash-outputmessage" visibility="public" name="outputMessage" returnType="string|null" params={[{"type":"string","name":"type","default":null},{"type":"mixed","name":"message","default":null}]}>
Outputs a message formatting it with HTML
</ApiItem>
<ApiItem href="#flashabstractflash-setautoescape" visibility="public" name="setAutoescape" returnType="static" params={[{"type":"bool","name":"autoescape","default":null}]}>
Set the autoescape mode in generated HTML
</ApiItem>
<ApiItem href="#flashabstractflash-setautomatichtml" visibility="public" name="setAutomaticHtml" returnType="static" params={[{"type":"bool","name":"automaticHtml","default":null}]}>
Set if the output must be implicitly formatted with HTML
</ApiItem>
<ApiItem href="#flashabstractflash-setcssclasses" visibility="public" name="setCssClasses" returnType="static" params={[{"type":"array","name":"cssClasses","default":null}]}>
Set an array with CSS classes to format the messages
</ApiItem>
<ApiItem href="#flashabstractflash-setcssiconclasses" visibility="public" name="setCssIconClasses" returnType="static" params={[{"type":"array","name":"cssIconClasses","default":null}]}>
Set an array with CSS classes to format the icon messages
</ApiItem>
<ApiItem href="#flashabstractflash-setcustomtemplate" visibility="public" name="setCustomTemplate" returnType="static" params={[{"type":"string","name":"customTemplate","default":null}]}>
Set a custom template for showing the messages
</ApiItem>
<ApiItem href="#flashabstractflash-setescaperservice" visibility="public" name="setEscaperService" returnType="static" params={[{"type":"EscaperInterface","name":"escaperService","default":null}]}>
Sets the Escaper Service
</ApiItem>
<ApiItem href="#flashabstractflash-setimplicitflush" visibility="public" name="setImplicitFlush" returnType="static" params={[{"type":"bool","name":"implicitFlush","default":null}]}>
Set whether the output must be implicitly flushed to the output or
</ApiItem>
<ApiItem href="#flashabstractflash-success" visibility="public" name="success" returnType="string|null" params={[{"type":"string","name":"message","default":null}]}>
Shows a HTML success message
</ApiItem>
<ApiItem href="#flashabstractflash-warning" visibility="public" name="warning" returnType="string|null" params={[{"type":"string","name":"message","default":null}]}>
Shows a HTML warning message
</ApiItem>

### Properties

<ApiItem kind="property" visibility="protected" name="autoescape" type="bool" default="true">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="automaticHtml" type="bool" default="true">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="cssClasses" type="array" default="[]">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="cssIconClasses" type="array" default="[]">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="customTemplate" type="string" default="&quot;&quot;">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="escaperService" type="EscaperInterface|null" default="null">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="implicitFlush" type="bool" default="true">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="messages" type="array" default="[]">
</ApiItem>
<ApiItem kind="property" visibility="protected" name="sessionService" type="SessionInterface|null" default="null">
</ApiItem>

### Methods

<h4 id="flashabstractflash-__construct"><code>__construct()</code></h4>

```php
public function __construct(
EscaperInterface|null $escaper = null,
SessionInterface|null $session = null
);
```

AbstractFlash constructor.

<h4 id="flashabstractflash-clear"><code>clear()</code></h4>

```php
public function clear(): void;
```

Clears accumulated messages when implicit flush is disabled

<h4 id="flashabstractflash-error"><code>error()</code></h4>

```php
public function error( string $message ): string|null;
```

Shows a HTML error message

```php
$flash->error("This is an error");
```

<h4 id="flashabstractflash-getautoescape"><code>getAutoescape()</code></h4>

```php
public function getAutoescape(): bool;
```

Returns the flag that defines whether to automatically escape content or not

<h4 id="flashabstractflash-getautomatichtml"><code>getAutomaticHtml()</code></h4>

```php
public function getAutomaticHtml(): bool;
```

Returns the flag that defines whether to automatically use HTML or not

<h4 id="flashabstractflash-getcssclasses"><code>getCssClasses()</code></h4>

```php
public function getCssClasses(): array;
```

Returns the array of the CSS classes for formatting messages. The key is
the type of message and the value is the CSS class

<h4 id="flashabstractflash-getcssiconclasses"><code>getCssIconClasses()</code></h4>

```php
public function getCssIconClasses(): array;
```

Returns the array of the icon CSS classes for formatting messages. The
key is the type of message and the value is the icon CSS class

<h4 id="flashabstractflash-getcustomtemplate"><code>getCustomTemplate()</code></h4>

```php
public function getCustomTemplate(): string;
```

Returns the custom template for formatting messages

<h4 id="flashabstractflash-getescaperservice"><code>getEscaperService()</code></h4>

```php
public function getEscaperService(): EscaperInterface;
```

Returns the Escaper Service

<h4 id="flashabstractflash-message"><code>message()</code></h4>

```php
abstract public function message(
string $type,
mixed $message
): string|null;
```

Outputs a message. Delivery semantics differ per implementation:
`Direct` renders and emits immediately, `Session` stores the raw
message for output on a later request.

<h4 id="flashabstractflash-notice"><code>notice()</code></h4>

```php
public function notice( string $message ): string|null;
```

Shows a HTML notice/information message

```php
$flash->notice("This is an information");
```

<h4 id="flashabstractflash-outputmessage"><code>outputMessage()</code></h4>

```php
public function outputMessage(
string $type,
mixed $message
): string|null;
```

Outputs a message formatting it with HTML

```php
$flash->outputMessage("error", $message);
```

<h4 id="flashabstractflash-setautoescape"><code>setAutoescape()</code></h4>

```php
public function setAutoescape( bool $autoescape ): static;
```

Set the autoescape mode in generated HTML

<h4 id="flashabstractflash-setautomatichtml"><code>setAutomaticHtml()</code></h4>

```php
public function setAutomaticHtml( bool $automaticHtml ): static;
```

Set if the output must be implicitly formatted with HTML

<h4 id="flashabstractflash-setcssclasses"><code>setCssClasses()</code></h4>

```php
public function setCssClasses( array $cssClasses ): static;
```

Set an array with CSS classes to format the messages

<h4 id="flashabstractflash-setcssiconclasses"><code>setCssIconClasses()</code></h4>

```php
public function setCssIconClasses( array $cssIconClasses ): static;
```

Set an array with CSS classes to format the icon messages

<h4 id="flashabstractflash-setcustomtemplate"><code>setCustomTemplate()</code></h4>

```php
public function setCustomTemplate( string $customTemplate ): static;
```

Set a custom template for showing the messages

<h4 id="flashabstractflash-setescaperservice"><code>setEscaperService()</code></h4>

```php
public function setEscaperService( EscaperInterface $escaperService ): static;
```

Sets the Escaper Service

<h4 id="flashabstractflash-setimplicitflush"><code>setImplicitFlush()</code></h4>

```php
public function setImplicitFlush( bool $implicitFlush ): static;
```

Set whether the output must be implicitly flushed to the output or
returned as string

Note: `output()` is an echo API and requires implicit flush to remain
enabled (the default). With implicit flush disabled, `message()` returns
the rendered string while `output()` does not emit it.

<h4 id="flashabstractflash-success"><code>success()</code></h4>

```php
public function success( string $message ): string|null;
```

Shows a HTML success message

```php
$flash->success("The process was finished successfully");
```

<h4 id="flashabstractflash-warning"><code>warning()</code></h4>

```php
public function warning( string $message ): string|null;
```

Shows a HTML warning message

```php
$flash->warning("Hey, this is important");
```

## Flash\Direct

Class

Class Direct

@package Phalcon\Flash

- `\stdClass`
- [`Phalcon\Di\AbstractInjectionAware`](/5.20/api/phalcon_di/#diabstractinjectionaware)
- [`Phalcon\Flash\AbstractFlash`](#flashabstractflash)
- **`Phalcon\Flash\Direct`**

### Method Summary

<ApiItem href="#flashdirect-message" visibility="public" name="message" returnType="string|null" params={[{"type":"string","name":"type","default":null},{"type":"mixed","name":"message","default":null}]}>
Outputs a message
</ApiItem>
<ApiItem href="#flashdirect-output" visibility="public" name="output" returnType="void" params={[{"type":"bool","name":"remove","default":"true"}]}>
Prints the messages accumulated in the flasher
</ApiItem>

### Methods

<h4 id="flashdirect-message"><code>message()</code></h4>

```php
public function message(
string $type,
mixed $message
): string|null;
```

Outputs a message

<h4 id="flashdirect-output"><code>output()</code></h4>

```php
public function output( bool $remove = true ): void;
```

Prints the messages accumulated in the flasher

## Flash\Exception

Class

Exceptions thrown in Phalcon\Flash classes will use this class

- `\Exception`
- **`Phalcon\Flash\Exception`**
- [`Phalcon\Flash\Exceptions\EscaperServiceUnavailable`](#flashexceptionsescaperserviceunavailable)
- [`Phalcon\Flash\Exceptions\FlashMessageNotStringOrArray`](#flashexceptionsflashmessagenotstringorarray)
- [`Phalcon\Flash\Exceptions\SessionServiceUnavailable`](#flashexceptionssessionserviceunavailable)

## Flash\Exceptions\EscaperServiceUnavailable

Class

- `\Exception`
- [`Phalcon\Flash\Exception`](#flashexception)
- **`Phalcon\Flash\Exceptions\EscaperServiceUnavailable`**

`Phalcon\Flash\Exception`

### Method Summary

<ApiItem href="#flashexceptionsescaperserviceunavailable-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="flashexceptionsescaperserviceunavailable-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Flash\Exceptions\FlashMessageNotStringOrArray

Class

- `\Exception`
- [`Phalcon\Flash\Exception`](#flashexception)
- **`Phalcon\Flash\Exceptions\FlashMessageNotStringOrArray`**

`Phalcon\Flash\Exception`

### Method Summary

<ApiItem href="#flashexceptionsflashmessagenotstringorarray-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="flashexceptionsflashmessagenotstringorarray-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Flash\Exceptions\SessionServiceUnavailable

Class

- `\Exception`
- [`Phalcon\Flash\Exception`](#flashexception)
- **`Phalcon\Flash\Exceptions\SessionServiceUnavailable`**

`Phalcon\Flash\Exception`

### Method Summary

<ApiItem href="#flashexceptionssessionserviceunavailable-__construct" visibility="public" name="__construct" returnType="" params={[]}>
</ApiItem>

### Methods

<h4 id="flashexceptionssessionserviceunavailable-__construct"><code>__construct()</code></h4>

```php
public function __construct();
```

## Flash\FlashInterface

Interface

Interface FlashInterface

- [`Phalcon\Contracts\Flash\Flash`](/5.20/api/phalcon_contracts/#contractsflashflash)
- **`Phalcon\Flash\FlashInterface`**

`Phalcon\Contracts\Flash\Flash`

## Flash\Session

Class

This is an implementation of the Phalcon\Flash\FlashInterface that
temporarily stores the messages in session, then messages can be printed in
the next request.

Class Session

@package Phalcon\Flash

- `\stdClass`
- [`Phalcon\Di\AbstractInjectionAware`](/5.20/api/phalcon_di/#diabstractinjectionaware)
- [`Phalcon\Flash\AbstractFlash`](#flashabstractflash)
- **`Phalcon\Flash\Session`**

`Phalcon\Contracts\Flash\FlashTypes` · `Phalcon\Flash\Exceptions\SessionServiceUnavailable` · `Phalcon\Html\Escaper\EscaperInterface` · `Phalcon\Session\ManagerInterface`

### Method Summary

<ApiItem href="#flashsession-__construct" visibility="public" name="__construct" returnType="" params={[{"type":"EscaperInterface|null","name":"escaper","default":"null"},{"type":"ManagerInterface|null","name":"session","default":"null"},{"type":"string|null","name":"sessionKey","default":"null"}]}>
Session constructor.
</ApiItem>
<ApiItem href="#flashsession-clear" visibility="public" name="clear" returnType="void" params={[]}>
Clear messages in the session messenger
</ApiItem>
<ApiItem href="#flashsession-getmessages" visibility="public" name="getMessages" returnType="array" params={[{"type":"mixed","name":"type","default":"null"},{"type":"bool","name":"remove","default":"true"}]}>
Returns the messages in the session flasher
</ApiItem>
<ApiItem href="#flashsession-getsessionservice" visibility="public" name="getSessionService" returnType="ManagerInterface" params={[]}>
Returns the Session Service
</ApiItem>
<ApiItem href="#flashsession-has" visibility="public" name="has" returnType="bool" params={[{"type":"string|null","name":"type","default":"null"}]}>
Checks whether there are messages
</ApiItem>
<ApiItem href="#flashsession-message" visibility="public" name="message" returnType="string|null" params={[{"type":"string","name":"type","default":null},{"type":"mixed","name":"message","default":null}]}>
Adds a message to the session flasher
</ApiItem>
<ApiItem href="#flashsession-output" visibility="public" name="output" returnType="void" params={[{"type":"bool","name":"remove","default":"true"}]}>
Prints the messages in the session flasher
</ApiItem>
<ApiItem href="#flashsession-getsessionmessages" visibility="protected" name="getSessionMessages" returnType="array" params={[{"type":"bool","name":"remove","default":null},{"type":"string|null","name":"type","default":"null"}]}>
Returns the messages stored in session
</ApiItem>
<ApiItem href="#flashsession-setsessionmessages" visibility="protected" name="setSessionMessages" returnType="array" params={[{"type":"array","name":"messages","default":null}]}>
Stores the messages in session
</ApiItem>

### Constants

<ApiItem kind="constant" name="SESSION_KEY" type="string" default="&quot;_flashMessages&quot;">
</ApiItem>

### Properties

<ApiItem kind="property" visibility="protected" name="sessionKey" type="string" default="&quot;&quot;">
</ApiItem>

### Methods

<h4 id="flashsession-__construct"><code>__construct()</code></h4>

```php
public function __construct(
EscaperInterface|null $escaper = null,
ManagerInterface|null $session = null,
string|null $sessionKey = null
);
```

Session constructor.

<h4 id="flashsession-clear"><code>clear()</code></h4>

```php
public function clear(): void;
```

Clear messages in the session messenger

<h4 id="flashsession-getmessages"><code>getMessages()</code></h4>

```php
public function getMessages(
mixed $type = null,
bool $remove = true
): array;
```

Returns the messages in the session flasher

<h4 id="flashsession-getsessionservice"><code>getSessionService()</code></h4>

```php
public function getSessionService(): ManagerInterface;
```

Returns the Session Service

<h4 id="flashsession-has"><code>has()</code></h4>

```php
public function has( string|null $type = null ): bool;
```

Checks whether there are messages

<h4 id="flashsession-message"><code>message()</code></h4>

```php
public function message(
string $type,
mixed $message
): string|null;
```

Adds a message to the session flasher

<h4 id="flashsession-output"><code>output()</code></h4>

```php
public function output( bool $remove = true ): void;
```

Prints the messages in the session flasher

<h4 id="flashsession-getsessionmessages"><code>getSessionMessages()</code></h4>

```php
protected function getSessionMessages(
bool $remove,
string|null $type = null
): array;
```

Returns the messages stored in session

<h4 id="flashsession-setsessionmessages"><code>setSessionMessages()</code></h4>

```php
protected function setSessionMessages( array $messages ): array;
```

Stores the messages in session

Source: https://docs.phalcon.io/5.20/api/phalcon_flash/index.mdx
