Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type of Flash Messenger in Zend

Is it possible or How can i give a type to a FlashMessage in Zend?

For example

/* This is a "Success" message */
$this -> _helper -> FlashMessenger('You are successfully created a post.'); 

/* This is an "Error" message  */
$this -> _helper -> FlashMessenger('There is an error while creating post.');

/* This is just a "Notification" message */
$this -> _helper -> FlashMessenger('Now you can see your Post');
like image 429
Mehmet Davut Avatar asked Oct 16 '10 20:10

Mehmet Davut


1 Answers

I think the best way to do this is by using the flashmessenger namespaces:

/* success message */
$this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Post created!');

/* error message */
$this->_helper->FlashMessenger()->setNamespace('error')->addMessage('You have no permissions');

And then in your layout you can get the messages added to each namespace:

<?php $flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');

<?php if ($flashMessenger->setNamespace('success')->hasMessages()): ?>
    <div class="message success">
    <?php foreach ($flashMessenger->getMessages() as $msg): ?>
        <?php echo $msg ?>
    <?php endforeach; ?>
    </div>
<?php endif; ?>

<?php if ($flashMessenger->setNamespace('error')->hasMessages()): ?>
    <div class="message error">
    <?php foreach ($flashMessenger->getMessages() as $msg): ?>
        <?php echo $msg ?>
    <?php endforeach; ?>
    </div>
<?php endif; ?>
like image 130
rafeca Avatar answered Sep 21 '22 15:09

rafeca