我使用ZF 1.12.3
索引中的我有
define('APPLICATION_ENV', 'development');
错误:
Notice: Trying to get property of non-object in application/controllers/ErrorController.php on line 28
在这一行我有
$errors = $this->_getParam('error_handler');
我喜欢添加
的解决方案Zend_Controller_Front::getInstance()->throwExceptions(false);
到boostrap - 但它没有解决我的错误
application.ini:
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
autoloaderNamespaces[] = "mea\"
includePaths.mea = APPLICATION_PATH "/../library/Vendor/mea"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.view[] =
appnamespace = "Application"
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
错误控制器:
<?php
class ErrorController extends Zend_Controller_Action
{
public function init()
{
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Application',
'basePath' => APPLICATION_PATH
));
ZendX_JQuery::enableView( $this->view);
}
public function errorAction()
{
$errors = $this->_getParam('error_handler');
if(!$errors){
}
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;
}
}
答案 0 :(得分:0)
这就是我认为的问题,你没有任何异常,但是你正试图直接运行你的错误控制器(我不知道为什么),
试试这个,
if($errors!=null){
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;
}
希望有所帮助,