Zend Framework路由引发应用程序错误,以便在URL上跟踪感叹号

时间:2012-09-26 14:39:51

标签: php zend-framework zend-route zend-router

我有一个视图,当访问“http:// localhost / public / account / test”时可以正常工作,但是当添加感叹号时(“http:// localhost / public / account / test!”) ,我收到一个应用程序错误;但是,我预计会发生404错误。控制器中只有一个testAction()方法,而不是test-Action()方法(好像PHP甚至可以让我侥幸逃脱)。我该怎么办才能得到404错误?

以下是我收到的应用程序错误的详细信息:

  

消息:路径中找不到脚本'account / test-.phtml'(/ website / application / modules / default / views / scripts /)

堆栈追踪:

    #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"
    }

2 个答案:

答案 0 :(得分: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:

答案 1 :(得分:0)

使用urlencode ...

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