简体   繁体   English

Zend Framework 1 Flash Messenger产生空数组

[英]Zend framework 1 flash messenger yields empty array

I'm trying to set a message in Zend Framework 1's flash messenger. 我正在尝试在Zend Framework 1的Flash Messenger中设置一条消息。 Then I'm outputting the result here as I was getting nothing in my view: 然后,我在这里输出结果,因为我认为没有任何结果:

public function successAction()
{
    $this->_helper->flashMessenger->addMessage('Account has been successfully created.');
    $this->view->messages = $this->_helper->flashMessenger->getMessages();
    var_dump($this->view->messages); exit;
}

..but it's just an empty array. ..但这只是一个空数组。 Is there anything else I have to do withing the framework, or with the helper to set and retrieve these? 与框架或帮助程序设置和检索它们还有其他关系吗?

Here is how I was trying to access it from 这是我试图从中访问它的方式

The FlashMessenger helper allows you to pass messages that the user may need to see on the next request. FlashMessenger帮助器允许您传递用户可能需要在下一个请求中看到的消息。 To accomplish this, FlashMessenger uses Zend_Session_Namespace to store messages for future or next request retrieval. 为此,FlashMessenger使用Zend_Session_Namespace存储消息以供将来或下一个请求检索。

You can see it in the doc 您可以在文档中看到它

So your message can be recovered in another action (other request). 因此,您可以在其他操作(其他请求)中恢复您的消息。

If you want to retrieve the message in the same action, you can try to use getCurrentMessages() : 如果要以相同的操作检索消息,则可以尝试使用getCurrentMessages()

$this->view->messages = this->_helper->flashMessenger->getCurrentMessages();

But if this message is only for one request, you can use Zend_Registry 但是,如果此消息仅用于一个请求,则可以使用Zend_Registry

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM