ZF2 2.5 并不总是显示完整的错误消息
ZF2 2.5 not always showing full error message
自从我将 Zend-Framework 更新到 2.5.3 版并将 PHP 更新到 7.0 版后,如果发生异常,我并不总能收到完整的错误消息。
例如:发生异常,我可以获得异常消息的唯一方法是使用调试器(Class:ExceptionStrategy,行:121):
在前端,只显示一般错误消息:
我已经打开 PHP 错误报告(在我的 local.php 和 php.ini 中):
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
奇怪的是,有时我会收到完整的错误消息,包括堆栈跟踪和调试所需的一切,但有时我只会收到一般错误消息。
我希望它看起来像这样:
有人经历过这种行为吗?这正常吗?
不确定这是否会导致您的问题,但无论如何值得一提。
您必须配置 view-manager 到 display/render 例外。您可以阅读有关如何在 ZF2 documentation here.
中配置视图渲染器的更多信息
视图管理器配置中有一个专用键:
'display_exceptions' => true,
好的,现在我找到了。问题出在我的错误模板中,因为有一个 if-statement 检查异常是否是 Exception:
的实例
<?php if(isset($this->exception) && $this->exception instanceof Exception): ?>
由于 PHP 7 大多数错误都报告了错误异常,所以我不得不像这样扩展 if-statement:
<?php if(isset($this->exception) && ($this->exception instanceof Exception || $this->exception instanceof Error)): ?>
自从我将 Zend-Framework 更新到 2.5.3 版并将 PHP 更新到 7.0 版后,如果发生异常,我并不总能收到完整的错误消息。
例如:发生异常,我可以获得异常消息的唯一方法是使用调试器(Class:ExceptionStrategy,行:121):
在前端,只显示一般错误消息:
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
奇怪的是,有时我会收到完整的错误消息,包括堆栈跟踪和调试所需的一切,但有时我只会收到一般错误消息。
我希望它看起来像这样:
有人经历过这种行为吗?这正常吗?
不确定这是否会导致您的问题,但无论如何值得一提。
您必须配置 view-manager 到 display/render 例外。您可以阅读有关如何在 ZF2 documentation here.
中配置视图渲染器的更多信息视图管理器配置中有一个专用键:
'display_exceptions' => true,
好的,现在我找到了。问题出在我的错误模板中,因为有一个 if-statement 检查异常是否是 Exception:
的实例<?php if(isset($this->exception) && $this->exception instanceof Exception): ?>
由于 PHP 7 大多数错误都报告了错误异常,所以我不得不像这样扩展 if-statement:
<?php if(isset($this->exception) && ($this->exception instanceof Exception || $this->exception instanceof Error)): ?>