【发布时间】:2012-02-18 01:22:01
【问题描述】:
在我的 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();
【问题讨论】:
-
ZF 哪个版本? 2011 年 7 月 14 日解决了 1.8.0 中的一个错误 - framework.zend.com/issues/browse/ZF-6650
标签: php zend-framework frameworks controller