简体   繁体   中英

Zend Framework routing throws an application error for trailing exclamation point on URL

I have a view that works correctly when "http://localhost/public/account/test" is visited, but when an exclamation point is added ("http://localhost/public/account/test!"), I get an application error; however, I'm expecting a 404 error to occur. There is only a testAction() method in the controller, not a test-Action() method (as if PHP even would let me get away with that). What can I do to get a 404 error to be throw instead?

Here is the details of the application error that I recieve:

Message: script 'account/test-.phtml' not found in path (/website/application/modules/default/views/scripts/)

Stack trace:

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

There is a place in ErrorController.php which looks something like this:

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;
}

You could adjust it a little bit to cover your case:

    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:

使用urlencode ...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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