2017-02-19 171 views
1

我試圖在視圖文件中顯示來自flashMessenger的消息。 加入他們控制器Zend框架2會話驗證失敗

$status = 'error'; 
$message = 'Wrong parameters'; 
$this->flashMessenger()->addMessage($message)->setNamespace($status); 

試圖在.phtml文件,以獲取信息:

1)所示$this->flashMessenger()->getPluginFlashMessenger()->getCurrentErrorMessages();

2)像這個

$flash = $this->flashMessenger(); 
if (count($flash->getMessages())) { 
    $flash->render('error'); 
} 

而且總能收到同樣的錯誤Session validation failed

調用堆棧:

#0 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/Session/AbstractContainer.php(78): Zend\Session\SessionManager->start() 
#1 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/FlashMessenger.php(120): Zend\Session\AbstractContainer->__construct('FlashMessenger', Object(Zend\Session\SessionManager)) 
#2 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/FlashMessenger.php(447): Zend\Mvc\Controller\Plugin\FlashMessenger->getContainer() 
#3 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/FlashMessenger.php(525): Zend\Mvc\Controller\Plugin\FlashMessenger->hasCurrentMessages() 
#4 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/FlashMessenger.php(593): Zend\Mvc\Controller\Plugin\FlashMessenger->getCurrentMessages() 
#5 /home/dmitriy/zend/module/Admin/view/admin/category/index.phtml(20): Zend\Mvc\Controller\Plugin\FlashMessenger->getCurrentErrorMessages() 
#6 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php(506): include('/home/dmitriy/z...') 
#7 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/View/View.php(205): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel)) 
#8 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/View/View.php(233): Zend\View\View->render(Object(Zend\View\Model\ViewModel)) 
#9 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/View/View.php(198): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel)) 
#10 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php(102): Zend\View\View->render(Object(Zend\View\Model\ViewModel)) 
#11 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent)) 
#12 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent)) 
#13 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('render', Object(Zend\Mvc\MvcEvent), Array) 
#14 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(355): Zend\EventManager\EventManager->trigger('render', Object(Zend\Mvc\MvcEvent)) 
#15 /home/dmitriy/zend/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(330): Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent)) 
#16 /home/dmitriy/zend/public/index.php(24): Zend\Mvc\Application->run() 
#17 {main} 

Zend粉碎之前顯示在視圖文件。這裏addMessage($message)

+0

'會話驗證失敗'錯誤讓我想起了這個問題和答案 - > http://stackoverflow.com/questions/17428778/zend-session-container-session-validation-failed -exception-objectclosure-zf – Crisp

+0

有沒有答案:(我不使用事件,只是嘗試使用zend的standart功能 –

回答

0

我通過添加「session_start();」在容器的開頭

+0

哪些容器? –