Zend Framework中的ErrorHandler

为了方便调试,在index.php中可以设置$frontController->throwExceptions(true),这样所有错误会直接显示在浏览器中

 

但是最后部署时候,可以删除该句,并且增加application/Controller/ErrorController.php,以及/application/views/script/error/error.html来引导用户到一个错误提示页面

并且可以将错误记录到log文件中:

 

  1. <?php
  2. /** Zend_Controller_Action */
  3. require_once 'Gado/Controller/Action.php';
  4. require_once 'Zend/Log.php';
  5. require_once 'Zend/Log/Writer/Stream.php';
  6. class ErrorController extends Gado_Controller_Action
  7. {
  8.     public function errorAction()
  9.     {
  10.         $errors = $this->_getParam('error_handler');
  11.         $request = $this->getRequest();
  12.         $exception = $errors->exception;
  13.         $log = new Zend_Log(new Zend_Log_Writer_Stream('./log/applicationException.log'));
  14.         $log->debug($request->getRequestUri());
  15.         $log->debug(var_export($_POST, true) ."/n". var_export($_GET, true));
  16.         $log->debug($exception->getMessage());
  17.         $log->debug($exception->getTraceAsString());
  18.     }
  19. }
  20. ?>

你可能感兴趣的:(Zend Framework中的ErrorHandler)