如何使Zend Framework错误页面看起来更清晰,更漂亮?

时间:2022-10-10 18:20:05

By default error page in ZF looks like this:

默认情况下,ZF中的错误页面如下所示:

Fatal error: Uncaught exception 'Zend_Form_Exception' with message 'Method setDeault does not exist' in /usr/home/.../library/Zend/Form.php:2838 
Stack trace: 
#0 [internal function]: Zend_Form->__call('setDeault', Array) 
#1 /usr/home/.../application/admin/controllers/TagsController.php(40): Web_Form_Admintags->setDeault('tagstext', '....') 
#2 /usr/home/.../library/Zend/

Is there any ways to change this messy error description to more clearly form (something like Django error page)?

有没有办法改变这个凌乱的错误描述更清楚的形式(像Django错误页面)?

3 个解决方案

#1


This is not an error page but a standard PHP output for uncaught exceptions. As far as I know there is no default error page in Zend Framework -- you will have to create your own by creating an appropriate view for the ErrorController.

这不是错误页面,而是未捕获异常的标准PHP输出。据我所知,Zend Framework中没有默认的错误页面 - 您必须通过为ErrorController创建适当的视图来创建自己的错误页面。

#2


AFAICR this is using the Error controller right? That message is basically the dump of the exception object. You can split this up by calling different parts individually rather than dumping the whole lot as a string. See the manual page I linked to.

AFAICR这是使用错误控制器吗?该消息基本上是异常对象的转储。您可以通过单独调用不同的部分而不是将整个部分转换为字符串来拆分它。请参阅我链接到的手册页。

Make sure you're only providing exception information when the APPLICATION_ENVIRONMENT is set to development as well.

当APPLICATION_ENVIRONMENT也设置为开发时,请确保您仅提供异常信息。

#3


The exception is formatted using new lines, which are however not transformed to
in html. You have several options...

使用新行格式化异常,但不会在html中转换为新行。你有几个选择......

  1. Wrap the error with <pre></pre> tags
  2.  
      
      标签包装错误

  3. Create custom exception handler
  4. 创建定制异常处理程序

 

function exception_handler($exception) {
  echo "Uncaught exception: " , $exception->getMessage(), "\n";
}

set_exception_handler('exception_handler');

#1


This is not an error page but a standard PHP output for uncaught exceptions. As far as I know there is no default error page in Zend Framework -- you will have to create your own by creating an appropriate view for the ErrorController.

这不是错误页面,而是未捕获异常的标准PHP输出。据我所知,Zend Framework中没有默认的错误页面 - 您必须通过为ErrorController创建适当的视图来创建自己的错误页面。

#2


AFAICR this is using the Error controller right? That message is basically the dump of the exception object. You can split this up by calling different parts individually rather than dumping the whole lot as a string. See the manual page I linked to.

AFAICR这是使用错误控制器吗?该消息基本上是异常对象的转储。您可以通过单独调用不同的部分而不是将整个部分转换为字符串来拆分它。请参阅我链接到的手册页。

Make sure you're only providing exception information when the APPLICATION_ENVIRONMENT is set to development as well.

当APPLICATION_ENVIRONMENT也设置为开发时,请确保您仅提供异常信息。

#3


The exception is formatted using new lines, which are however not transformed to
in html. You have several options...

使用新行格式化异常,但不会在html中转换为新行。你有几个选择......

  1. Wrap the error with <pre></pre> tags
  2.  
      
      标签包装错误

  3. Create custom exception handler
  4. 创建定制异常处理程序

 

function exception_handler($exception) {
  echo "Uncaught exception: " , $exception->getMessage(), "\n";
}

set_exception_handler('exception_handler');