Skip to content

Instantly share code, notes, and snippets.

@m4tm4t
Last active January 3, 2016 13:29
Show Gist options
  • Save m4tm4t/8470086 to your computer and use it in GitHub Desktop.
Save m4tm4t/8470086 to your computer and use it in GitHub Desktop.
Zend 2 crazy flash notices with namespaces
<?php
// Set message
$this->flashMessenger()
->setNamespace("success")
->addMessage("You've been logged out");
return $this->redirect()->toUrl('/');
// Retrieve message
$notice = null;
$flash = $this->flashMessenger();
$flash->setNamespace('success');
if ($flash->hasMessages())
$notice = array('type' => 'success', 'message' => $flash->getMessages()[0]);
$flash->setNamespace('error');
if ($flash->hasMessages())
$notice = array('type' => 'error', 'message' => $flash->getMessages()[0]);
$this->layout()->notice = $notice;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment