On this page

mezzio-flash

Flash messages are self-expiring, session-based messages. They are typically used when when you need to redirect after processing a request (e.g., when using the Post-Redirect-Get pattern), but want to display a message back to the user indicating a processing result.

As an example, I may want to display a "Thank You" message to the user after successfully completing a form. I can do that with flash messages.

When processing, I would create the message in my middleware:

$flashMessages->flash('form-complete', 'Thank you; your submission was recorded.');

On the subsequent request, my middleware would pull that message:

$message = $flashMessages->getFlash('form-complete');

On any subsequent requests, the message is no longer available!

Installation

To use the component, install via Composer:

$ composer require mezzio/mezzio-flash

Persistence required

mezzio-flash depends on mezzio-session, which defines abstractions around session containers — for use within applications for accessing session data — and session persistence (how the session data is persisted between requests, and reported to the client).

Persistence requires a persistence adapter. We offer one basd on PHP's session extension via the package mezzio-session-ext; others may also be available soon.

Found a mistake or want to contribute to the documentation? Edit this page on GitHub!