2014-03-13 49 views
0

我有一個基於Zend Framework 2的大型網站。URL遵循domain.tld/module/action/otherstuff的標準模式。ZF2如何顯示錯誤404爲不可伸縮動作

如果有人鍵入一個不存在的模塊,他們會得到一個標準的404頁未找到消息。但是,如果用戶進入一個有效的模塊,而是進入一個無效的動作名稱,他們得到的消息

Zend\View\HelperPluginManager::get was unable to fetch or create an instance for escape 

我怎麼能輸出一個正常的404錯誤消息,而不是此消息?我猜測我沒有在某處正確地捕捉到某些東西,但我不知道從哪裏開始尋找。

這裏是堆棧跟蹤:

C:\conversion\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.phpLine #495 
#0 C:\conversion\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php(103): Zend\ServiceManager\ServiceManager->get('escape', true) 
#1 C:\conversion\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php(378): Zend\ServiceManager\AbstractPluginManager->get('escape', NULL) 
#2 C:\conversion\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php(397): Zend\View\Renderer\PhpRenderer->plugin('escape') 
#3 C:\conversion\module\Supplier\view\error\404.phtml(56): Zend\View\Renderer\PhpRenderer->__call('escape', Array) 
#4 C:\conversion\module\Supplier\view\error\404.phtml(56): Zend\View\Renderer\PhpRenderer->escape('Supplier\Contro...') 
#5 C:\conversion\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php(507): include('C:\conversio...') 
#6 C:\conversion\vendor\zendframework\zendframework\library\Zend\View\View.php(205): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel)) 
#7 C:\conversion\vendor\zendframework\zendframework\library\Zend\View\View.php(233): Zend\View\View->render(Object(Zend\View\Model\ViewModel)) 
#8 C:\conversion\vendor\zendframework\zendframework\library\Zend\View\View.php(198): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel)) 
#9 C:\conversion\vendor\zendframework\zendframework\library\Zend\Mvc\View\Http\DefaultRenderingStrategy.php(102): Zend\View\View->render(Object(Zend\View\Model\ViewModel)) 
#10 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent)) 
#11 C:\conversion\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent)) 
#12 C:\conversion\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('render', Object(Zend\Mvc\MvcEvent), Array) 
#13 C:\conversion\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(347): Zend\EventManager\EventManager->trigger('render', Object(Zend\Mvc\MvcEvent)) 
#14 C:\conversion\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(322): Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent)) 
#15 C:\conversion\public\index.php(25): Zend\Mvc\Application->run() 
#16 {main}    
+0

您可以發佈您完整的堆棧跟蹤? zf2中沒有'逃生'視圖助手。看起來像你的一個視圖文件搞亂了某個地方。 – radnan

+0

添加堆棧跟蹤 – Wige

+1

用escapeHtml()替換#4中的escape()。 – radnan

回答

1

在module.config.php

'view_manager' => array(
     'display_not_found_reason' => true, 
     'display_exceptions' => true, 
     'doctype' => 'HTML5', 
     'not_found_template' => 'error/404', 
     'exception_template' => 'error/index', 
     'template_map' => array(
      'application/index/changelocal' => __DIR__ . '/../view/application/index/changelocal.phtml', 
      'application/index/index' => __DIR__ . '/../view/application/index/index.phtml', 
      'error/404' => __DIR__ . '/../view/error/404.phtml', 
      'error/index' => __DIR__ . '/../view/error/index.phtml', 
     ), 
     'template_path_stack' => array(
      __DIR__ . '/../view', 
     ), 
    ) 
+0

這讓我更接近至少,謝謝。如果我沒有創建模板映射中列出的404.phtml文件,我會收到一條消息,指出它正在嘗試查找該文件,但無法找到該文件。但是,當我創建錯誤404.phtml文件時,它會輸出錯誤/ index.phtml內容,而將上面的堆棧跟蹤添加到原始問題中。 – Wige