Created
August 2, 2011 13:05
-
-
Save harikt/1120132 to your computer and use it in GitHub Desktop.
Flash Messages in ZF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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