zend 框架错误控制器不处理 EXCEPTION_NO_CONTROLLER
在我的 Zend Framework 项目中,我的错误控制器不处理 EXCEPTION_NO_CONTROLLER 异常。当我调试错误控制器时,它确实进入 EXCEPTION_NO_CONTROLLER 开关块并执行方法中的每个步骤,但我的 error.phtml 没有被渲染。它向我显示致命错误而不是 error.phtml 视图。它处理 EXCEPTION_NO_ACTION 和默认块并呈现 error.phtml 视图。我不明白问题是什么或者我错过了什么。
这是错误控制器代码中的错误操作:
public function errorAction()
{
$errors = $this->_getParam('error_handler');
if (!$errors) {
$this->view->message = 'You have reached the error page';
return;
}
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'no such module exist';
break;
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'no such module exist';
break;
default:
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = 'an application error occurred';
break;
}
// Log exception, if logger available
//if ($log == $this->getLog()) {
// $log->crit($this->view->message, $errors->exception);
//}
// conditionally display exceptions
if ($this->getInvokeArg('displayExceptions') == true) {
$this->view->exception = $errors->exception;
}
$this->view->request = $errors->request;
}
当我键入任何无效控制器时,我收到以下致命错误:
Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script' not found in path .....................
以下是我的 index.php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
set_include_path(implode(PATH_SEPARATOR, array(
'/home/sampleproj/www/library/',
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
In my Zend Framework project, my Error controller is not handling EXCEPTION_NO_CONTROLLER exception. When I debug the Error controller, it does enter the EXCEPTION_NO_CONTROLLER switch block and goes through each and every step in the method but my error.phtml is not being rendered. It shows me the fatal error instead of error.phtml view. It handles the EXCEPTION_NO_ACTION and default block and renders the error.phtml view. I don't understand what the problem is or what I'm missing.
Here is my error action in error controller code:
public function errorAction()
{
$errors = $this->_getParam('error_handler');
if (!$errors) {
$this->view->message = 'You have reached the error page';
return;
}
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'no such module exist';
break;
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'no such module exist';
break;
default:
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = 'an application error occurred';
break;
}
// Log exception, if logger available
//if ($log == $this->getLog()) {
// $log->crit($this->view->message, $errors->exception);
//}
// conditionally display exceptions
if ($this->getInvokeArg('displayExceptions') == true) {
$this->view->exception = $errors->exception;
}
$this->view->request = $errors->request;
}
And I receive the following fatal error when I type any invalid controller:
Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script' not found in path .....................
Following is my index.php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
set_include_path(implode(PATH_SEPARATOR, array(
'/home/sampleproj/www/library/',
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在文件夹
/scripts/errors/
中创建视图文件 error.phtml(带有一些 html 代码)You need to create view file error.phtml(with some htlm code) in folder
/scripts/errors/