Skip to content

Instantly share code, notes, and snippets.

@harikt
Created August 2, 2011 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harikt/1120132 to your computer and use it in GitHub Desktop.
Save harikt/1120132 to your computer and use it in GitHub Desktop.
Flash Messages in ZF
<?php
//In controller
//Read http://akrabat.com/zend-framework/zend-frameworks-flash-messenger-action-helper/
if( $some_condition ) {
$this->_helper->flashMessenger->addMessage('Task saved');
$this->_redirect('admin/tours');
}
//Get all flash messengers
$this->view->messages = $this->_helper->flashMessenger->getMessages();
//The above will work as it redirects and calls the action again. The message will be there to show .
//But if we are forwarding or you want to show the message in the current action itself .
//We want to call getCurrentMessages()
$this->_helper->flashMessenger->addMessage('Want to say something now itself ? ');
$this->view->messages = array_merge(
$this->_helper->flashMessenger->getMessages(),
$this->_helper->flashMessenger->getCurrentMessages()
);
//We are clearing the current messages so that it will not show again in the next time.
$this->_helper->flashMessenger->clearCurrentMessages();
//In view , you can add in layout :-)
<div class="errors">
<?php if (count($this->messages)) : ?>
<ul id="messages">
<?php foreach ($this->messages as $message) : ?>
<li><?php echo $this->escape($message); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment