Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Zend Mvc Plugin Flashmessenger Laravel Package

zendframework/zend-mvc-plugin-flashmessenger

Zend Framework MVC plugin that provides a flash messenger for carrying short status messages across redirects. Messages are stored in the session for the next request and then cleared automatically, making it easy to show success or error notices in your views after a redirect.

View on GitHub
Deep Wiki
Context7

Getting Started

This is not a Laravel package — it ships zend-mvc-plugin-flashmessenger, a controller plugin + view helper for Zend Framework / zend-mvc. Requiring it in a Laravel app does nothing useful: there is no service provider, no facade, no auto-discovery, and the classes expect a zend-mvc ServiceManager and Zend\Session container. Treat it as a package you touch when maintaining a legacy ZF application alongside your Laravel work.

  • Install (legacy ZF app only): composer require zendframework/zend-mvc-plugin-flashmessenger:^1.2
  • Where to look first: the controller plugin Zend\Mvc\Plugin\FlashMessenger\FlashMessenger (add/get/render messages) and the view helper Zend\Mvc\Plugin\FlashMessenger\View\Helper\FlashMessenger (markup rendering in .phtml templates).
  • What 1.2.0 changed for you: PHP 7.3 is now supported, zend-stdlib v2 is no longer supported (you must be on v3), and a new Zend\Mvc\Plugin\FlashMessenger\View\HelperTrait gives you IDE autocompletion for $this->flashMessenger() inside templates.
  • First use case: flash a success message in a ZF controller, redirect, and render it in the next request's layout — the same pattern you'd reach for in Laravel with redirect()->with() + a Blade partial.

The Laravel equivalent you'll actually write day-to-day:

return redirect()->route('orders.index')->with('success', 'Order created.');
@if (session('success'))
    <div class="alert alert-success">{{ session('success') }}</div>
@endif

The value of this package to you is understanding the ZF contract so a bridge/shim or a port behaves identically.

Implementation Patterns

1. Controller-side flash (ZF). Messages are queued during the request, persisted to the session on dispatch, and read back on the next request:

$this->flashMessenger()->addSuccessMessage('Order created.');
$this->flashMessenger()->addErrorMessage('Payment declined.');

// Namespaced messages for a specific form/flow
$this->flashMessenger()->addMessage('Saved as draft.', 'orders');

return $this->redirect()->toRoute('orders');

2. View-side rendering with markup classes. The helper takes a namespace and CSS classes, so it slots straight into Bootstrap-style layouts:

// layout.phtml
echo $this->flashMessenger()->render('success', ['alert', 'alert-success']);
echo $this->flashMessenger()->render('error',   ['alert', 'alert-danger']);
echo $this->flashMessenger()->render('orders',  ['alert', 'alert-info']);

3. IDE autocompletion (new in 1.2.0). Add the trait to your template's docblock so $this resolves helper methods:

<?php /** @var \Zend\View\Renderer\PhpRenderer|\Zend\Mvc\Plugin\FlashMessenger\View\HelperTrait $this */ ?>

This is the ZF analogue of Laravel's @method/@property docblocks and _ide_helper.php — purely developer experience, no runtime effect.

4. Bridge pattern when you run both frameworks. If you must surface ZF-generated flashes inside a Laravel view during a migration, normalise at the boundary rather than copying markup:

// Legacy ZF side: write to the shared session under a stable key
$this->flashMessenger()->addMessage($msg, 'laravel_bridge');

// Laravel side: a small view composer / Blade component reads that key once
// and clears it, mirroring the "one request only" flash semantics.

5. Laravel-native pattern to mirror it. Prefer framework primitives in Laravel rather than pulling zend-mvc in:

session()->flash('status', 'Profile updated.');   // survives one request
session()->now('status', 'Saved.');               // available immediately
session()->reflash();                             // extend lifetime

6. Standardise your own helper. In either stack, wrap rendering in one component (<x-flash />) so success/error/warning markup is defined once and tests can assert against a single entry point.

Gotchas and Tips

  • Framework mismatch is the top gotcha. There is no Laravel integration here. Don't add it to a Laravel composer.json hoping for auto-discovery; you'd get dead weight and possible Zend\Stdlib conflicts.
  • Breaking-ish dependency change in 1.2.0: zend-stdlib v2 support is removed. If anything in your legacy app is pinned to zendframework/zend-stdlib:^2, upgrading this package will break resolution. Check composer why zendframework/zend-stdlib before bumping.
  • PHP 7.3 added, not required. "Adds support for PHP 7.3" means the test matrix now covers it; it does not raise the minimum. But note the package line ends here — the successor is laminas/laminas-mvc-plugin-flashmessenger, which is where PHP 8.x support lives. Plan the rename on any long-lived ZF app.
  • Flash lifetime is exactly one subsequent request. Messages are read from the session and cleared as part of the next request's lifecycle. Two redirects forward, they're gone. Don't use them for durable notices.
  • Session must be wired. If the ZF SessionManager isn't configured or the session isn't started, messages silently disappear between requests — a common "why is my flash empty?" bug. Verify the session container, not the plugin.
  • Namespace mismatches fail silently. addMessage($msg, 'orders') requires render('orders'); rendering the default namespace shows nothing and vice versa. Always pass the namespace explicitly.
  • Rendering consumes per-namespace state within the request. Render each namespace exactly once from the layout; render the same one twice and the second call returns empty, which breaks partials that "helpfully" re-render the layout block.
  • No HTML escaping concerns at the helper level — the helper escapes message text and only takes classes as a second argument. Never pre-wrap messages in HTML; pass plain text and let the classes do the styling.
  • Extending the plugin is the sanctioned extension point: subclass FlashMessenger and add addWarningMessage()/addInfoMessage() plus convenience accessors, then register it in controller_plugins. This keeps render() calls symmetric.
  • Testing: in a ZF app, mock the plugin and the session container; assert the plugin received addMessage with the right namespace rather than asserting on rendered HTML. In Laravel, the equivalent is assertSessionHas('success', ...) — write the assertion style you'd want after a port so migration doesn't rewrite tests.
  • The new ViewHelperTrait is docblock-only. It changes no behaviour and cannot break your templates, so it's a safe upgrade on its own — the real reason to pause on 1.2.0 is the stdlib constraint.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console