2012-09-26 21 views
0

我有一個視圖在訪問「http:// localhost/public/account/test」時正常工作,但當添加感嘆號時(「http :// localhost/public/account/test!「),我得到一個應用程序錯誤;不過,我期待404錯誤發生。在控制器中只有testAction()方法,而不是test-Action()方法(就像PHP甚至會讓我離開那樣)。我能做些什麼來獲得404錯誤,而不是拋出?Zend Framework路由引發URL上尾隨感嘆號的應用程序錯誤

這裏是應用程序錯誤的,我收到的細節:

消息:腳本「賬戶/測試一個.phtml」不在路徑(/網站/應用/模塊/默認/視圖/腳本發現/)

堆棧跟蹤:

#0 /Applications/XAMPP/xamppfiles/lib/php/pear/Zend/View/Abstract.php(876): Zend_View_Abstract->_script('account/test-.p...') 
    #1 /Applications/XAMPP/xamppfiles/lib/php/pear/Zend/Controller/Action/Helper/ViewRenderer.php(897): Zend_View_Abstract->render('account/test-.p...') 
    #2 /Applications/XAMPP/xamppfiles/lib/php/pear/Zend/Controller/Action/Helper/ViewRenderer.php(918): Zend_Controller_Action_Helper_ViewRenderer->renderScript('account/test-.p...', NULL) 
    #3 /Applications/XAMPP/xamppfiles/lib/php/pear/Zend/Controller/Action/Helper/ViewRenderer.php(957): Zend_Controller_Action_Helper_ViewRenderer->render() 
    #4 /Applications/XAMPP/xamppfiles/lib/php/pear/Zend/Controller/Action/HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch() 
    #5 /Applications/XAMPP/xamppfiles/lib/php/pear/Zend/Controller/Action.php(523): Zend_Controller_Action_HelperBroker->notifyPostDispatch() 
    #6 /Applications/XAMPP/xamppfiles/lib/php/pear/Zend/Controller/Dispatcher/Standard.php(289): Zend_Controller_Action->dispatch('testAction') 
    #7 /Applications/XAMPP/xamppfiles/lib/php/pear/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) 
    #8 /Applications/XAMPP/xamppfiles/lib/php/pear/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch() 
    #9 /Applications/XAMPP/xamppfiles/lib/php/pear/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() 
    #10 /website/public/index.php(42): Zend_Application->run() 
    #11 {main} 
    Request Parameters: 
    array(3) { 
     ["controller"]=> 
     string(7) "account" 
     ["action"]=> 
     string(5) "test!" 
     ["module"]=> 
     string(7) "default" 
    } 

回答

0

使用進行urlencode ...

testAction(urlencode("http://localhost/public/account/test!")) 
1

有一個在ErrorController.php的地方,看起來是這樣的:

public function errorAction() 
{ 
    $errors = $this->_getParam('error_handler'); 

    switch ($errors->type) { 
     case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: 
     case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: 

      // 404 error -- controller or action not found 
      $this->getResponse()->setHttpResponseCode(404); 
      $this->view->message = 'Page not found'; 
      break; 
     default: 
      // application error 
      $this->getResponse()->setHttpResponseCode(500); 
      $this->view->message = 'Application error'; 
      break; 
    } 

    $this->view->exception = $errors->exception; 
    $this->view->request = $errors->request; 
} 

你可以調整它一點點覆蓋你的情況:

switch ($errors->type) { 
     case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: 
     case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: 
     case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER: