Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.27 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.     //In controller
  3.     //Read http://akrabat.com/zend-framework/zend-frameworks-flash-messenger-action-helper/
  4.     if( $some_condition ) {
  5.         $this->_helper->flashMessenger->addMessage('Task saved');
  6.         $this->_redirect('admin/tours');
  7.     }
  8.     //Get all flash messengers
  9.     $this->view->messages = $this->_helper->flashMessenger->getMessages();
  10.     //The above will work as it redirects and calls the action again. The message will be there to show .
  11.    
  12.  
  13.     //But if we are forwarding or you want to show the message in the current action itself .
  14.     //We want to call getCurrentMessages()
  15.     $this->_helper->flashMessenger->addMessage('Want to say something now itself ? ');
  16.     $this->view->messages = array_merge(
  17.         $this->_helper->flashMessenger->getMessages(),
  18.         $this->_helper->flashMessenger->getCurrentMessages()
  19.     );
  20.     //We are clearing the current messages so that it will not show again in the next time.
  21.     $this->_helper->flashMessenger->clearCurrentMessages();
  22.  
  23.  
  24.  
  25. //In view , you can add in layout :-)
  26. <div class="errors">
  27. <?php if (count($this->messages)) : ?>
  28.     <ul id="messages">
  29.     <?php foreach ($this->messages as $message) : ?>
  30.         <li><?php echo $this->escape($message); ?></li>
  31.     <?php endforeach; ?>
  32.     </ul>
  33.     <?php endif; ?>
  34. </div>