3
目前我使用的是基本的錯誤控制器,它看起來是這樣的:捕獲和Zend Framework中記錄致命錯誤,警告,通知
class ErrorController extends My_MyController
{
public function errorAction()
{
$errors = $this->_getParam('error_handler');
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
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()
->setRawHeader('HTTP/1.1 404 Not Found');
$this->view->headTitle('HTTP/1.1 404 Not Found');
$this->view->message = 'HTTP/1.1 404 Not Found';
break;
default:
// application error; display error page, but don't change
// status code
// Log the exception:
$exception = $errors->exception;
$log = new Zend_Log(
new Zend_Log_Writer_Stream(
BASE_PATH . '/logs/applicationException.log'
)
);
$log->debug($exception->getMessage() . "\n" .
$exception->getTraceAsString());
$this->view->headTitle('HTTP/1.1 404 Not Found');
$this->view->message = 'Application error';
break;
}
$this->view->exception = $errors->exception;
}
}
然而,這僅捕獲和記錄應用程序異常。它不會記錄任何警告,通知和致命錯誤。
我想記錄這些。在ErrorController中有推薦的方法嗎?或者應該在index.php中的ErrorController之外完成(因爲Zend Framework ErrorHandler將只處理沒有路由,缺少動作控制器中的應用程序/動作異常和異常)?
這裏是我發現的實現,只需添加日誌某處有http://blog.jtclark.ca/2010/12/make-您-的Zend框架錯誤控制器手柄-PHP-錯誤/ – max4ever 2011-06-30 10:47:56