Zend Framework 2 Flash Messenger does not return messages

I have a rather strange problem with the flash messenger in ZF2. I use it in a fairly simple scenario, saving the message "registration is complete" after registering and redirecting to the login page and displaying the message, however, the messages are never returned by the flash messenger.

In the action of the controller register:

$this->flashMessenger()->addMessage('Registration complete');
return $this->redirect()->toRoute('default', array('controller' => 'user', 'action' => 'login'));

In the action of entering the controller:

$flashMessenger = $this->flashMessenger();
$mes = $flashMessenger->hasMessages();
$cur = $flashMessenger->hasCurrentMessages();

Both $ mes and $ cur are false (I tried to make sure). Can anyone shed some light on this?

I am using ZF 2.2.2 and PHP 5.3.14. The session persistence handler uses the dbtable adapter, and I tried to disable it, and also set the flashmessenger session manager to use the same dbtable persistent handler with no result.

+4
5

FlashMessenger, :

<?php 
class IndexController extends AbstractActionController {

  public function indexAction() {

    $this->flashMessenger()->addMessage('Your message');

    return $this->redirect()->toRoute('admin/default', array('controller'=>'index', 'action'=>'thankyou'));
  }

  public function thankyouAction() {

    return new ViewModel();
  }

}

thankyou.phtml :

<?php 

if ($this->flashMessenger()->hasMessages()) {

    echo '<div class="alert alert-info">';

    $messages = $this->flashMessenger()->getMessages();
    foreach($messages as $message) {
        echo $message;
    }

    echo '</div>';
}

?>
+6

, , - .

: var_dump($_SESSION), , FlashMessenger.

+2

echo $this->flashMessenger()->renderCurrent(...

echo $this->flashMessenger()->render(...
+2

(login flashmessage ). .

,

<?php if($this->zfcUserIdentity()) {  ?> 
                        <div id="flashMessageDiv" class="hide">
                            <?php echo isset($flashMessages) && isset($flashMessages['0']) ? $flashMessages['0'] : ''; ?>
                        </div>
                    <?php } ?>

, flashMessageDiv . (login.phtml)

   <?php $pathArray = $_SERVER['HTTP_REFERER'];
            $pathArray = explode("/",$pathArray);
        ?>

       <?php if ($pathArray[4] === 'register') { ?>   
            <div id="flashMessageDiv" class="hide">
                <?php  echo "User details saved successfully"; ?>
            </div>
       <?php } ?>

HTTP_REFERER, URL-, , URL- , show falshmessage.

, .

0

FlashMessenger ZF2 /: FlashMessenger - Zend Framework 2 2.3.1 - Zend Framework

TwitterBootstrap3 module.config.php.

-1

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


All Articles