[英]Zend Framework routing throws an application error for trailing exclamation point on URL
當訪問“ http:// localhost / public / account / test”時,我有一個視圖可以正常工作,但是當添加感嘆號(“ http:// localhost / public / account / test!”)時,我得到一個視圖應用程序錯誤; 但是,我預計會發生404錯誤。 控制器中只有testAction()
方法,而沒有test-Action()
方法(就好像PHP會讓我擺脫它一樣)。 我該怎么辦才能引發404錯誤?
這是我收到的應用程序錯誤的詳細信息:
消息:在路徑(/ website / application / modules / default / views / scripts /)中找不到腳本'account / test-.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"
}
在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:
使用urlencode ...
testAction(urlencode("http://localhost/public/account/test!"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.