Splitting FlashMessenger Messages in Zend Framework

What is the easiest way to categorize (warn, succeed, fail) flash messages in the Zend Framework using the FlashMessenger assistant? I also want one method to check messages in which the controller may not necessarily redirect the request. At the moment, I believe this is done through FlashMessenger :: getCurrentMessage ()?

+3
source share
3 answers

In the controller you can do this:

$this->_helper->FlashMessenger(
    array('error' => 'There was a problem with your form submission.') 
);
$this->_helper->FlashMessenger(
    array('notice' => 'Notice you forgot to input smth.') 
);

In the view, you can repeat the notification as follows:

<?php echo $this->flashMessenger('notice'); ?>

And an error like this:

<?php echo $this->flashMessenger('error'); ?>

Edit:

Check this link :

... getMessages() . , ZendSession FlashMessenger. , , ZendSession ( FlashMessenger ), getMessages().

FlashMessenger getCurrentMessages() ( ), , .

+10

.

1. PHPPlaneta​​STRONG >

PHPlaneta Robert Basic:

https://github.com/robertbasic/phpplaneta

FlashMessenger:

$this->_helper->flashMessenger()->addMessage(array('fm-bad' => 'Error occurred')

FlashMessenger, . script :

<?php echo $this->flashMessenger(); ?>

(ex: 'fm-bad') CSS .

2. PriorityMessenger

Priority Messenger Sean P. O. MacCath-Moran:

http://emanaton.com/code/php/zendprioritymessenger

, , , , . . script .

+2

, , .

, Zend_Controller_Action, , postDispatch() getCurrentMessages getMessages .

public function postDispatch()
{
    $messages = array_merge(
        $this->_helper->flashMessenger->getCurrentMessages(),
        $this->_helper->flashMessenger->getMessages()
    );
    $this->view->messages = count($messages) > 0 ? $messages[0] : array();
}

, :

$this->_helper->flashMessenger(array('error'=>'This is an error'));

$messages,

<?php if(count($this->messages) > 0) : ?>
//.. my HTML e.g. key($this->messages) returns 'error'
// current($this->messages) returns 'This is an error'
<?php endif; ?>

This works for me, as messages are classified and can be retrieved from the current request in addition to the next redirect.

+2
source

Source: https://habr.com/ru/post/1789257/


All Articles