使用 Zend 框架时显示 php 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1201709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 01:30:38  来源:igfitidea点击:

Display php errors when using Zend framework

phpzend-framework

提问by Ethan

I've been using Zend Framework and just living with this problem for a while, but it's now just gotten too annoying so i'll send the question out to you.

我一直在使用 Zend Framework 并且遇到这个问题已经有一段时间了,但是现在它变得太烦人了,所以我将问题发送给您。

There are certain problems within the Zend framework that Zend can recognize (such as calling a nonexistent controller), and will send that problem to the ErrorController. I've got that working fine.

Zend 可以识别 Zend 框架内的某些问题(例如调用不存在的控制器),并将该问题发送到 ErrorController。我的工作正常。

There seem to be some problems that Zend Framework will fail and display the error through php, like if a certain function doesn't exist or something. Those I can see and fix.

Zend Framework 似乎会出现一些问题,并通过 php 显示错误,例如某个函数不存在或什么的。那些我可以看到并修复的。

Sometimes though, Zend won't fail, but it will also just send out an empty response. I will get a blank page. They layout doesn't show up, there's no code, there's no nothing to give me an idea of what's gone wrong. Last time, there was a require() that failed. I had to manually figure this out with no feedback.

有时,虽然 Zend 不会失败,但它也会发出一个空响应。我会得到一个空白页。他们的布局没有显示,没有代码,没有任何东西可以让我知道出了什么问题。上次,有一个 require() 失败了。我不得不在没有反馈的情况下手动解决这个问题。

Have any of you experienced this? Do you have any advice on how to get these errors to show? Any help would be appreciated!

你们中有人经历过吗?您对如何显示这些错误有什么建议吗?任何帮助,将不胜感激!

回答by jason

The internal error handling of the framework's MVC components can only trap Exceptions, not PHP errors.

框架的 MVC 组件的内部错误处理只能捕获异常,而不是 PHP 错误。

To assist in debugging during development, you can use the standard:

为了在开发过程中协助调试,您可以使用标准:

error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 'on');

Also, if you're using the new Autoloader included with 1.8, use:

此外,如果您使用的是 1.8 附带的新自动加载器,请使用:

Zend_Loader_Autoloader::getInstance()->suppressNotFoundWarnings(false);

To allow failed include/require statements to be issued.

允许发出失败的包含/要求语句。

回答by Niels Bom

For others coming across this question: I changed the following line in configs/application.ini

对于遇到此问题的其他人:我在 configs/application.ini 中更改了以下行

resources.frontController.params.displayExceptions = 0

To:

到:

resources.frontController.params.displayExceptions = 1

This allowed me to see the full Exception, including stacktrace.

这让我可以看到完整的异常,包括堆栈跟踪。

回答by Kamilos

Set this in your config:

在您的配置中设置:

phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

回答by Brian

Edit the file public/index.php.
Change the APPLICATION_ENV to 'development'.

编辑文件 public/index.php。
将 APPLICATION_ENV 更改为“开发”。

This will use the development settings in your application/configs/application.ini file. Those settings define whether to suppress errors.

这将使用 application/configs/application.ini 文件中的开发设置。这些设置定义是否抑制错误。

回答by Jay Bhatt

It's too late to answer this question now. But hope it will help someone else...

现在回答这个问题为时已晚。但希望它会帮助别人......

Just place the following function in your Bootstrap.php file to enable exceptions..

只需将以下函数放在 Bootstrap.php 文件中即可启用异常。

protected function _initErrorDisplay(){
        $frontController = Zend_Controller_Front::getInstance();
        $frontController->throwExceptions(true);
    }

回答by Vasiliy Toporov

Fast and dirty decision, if none of already mentioned methods worked (useful for old or ugly-configured version of ZF):

快速和肮脏的决定,如果已经提到的方法都不起作用(对于旧的或配置丑陋的 ZF 版本很有用):

  • find ErrorController of your application.
  • put the call of debug_print_backtrace function at the top of init method (with die() optionally)
  • 找到您的应用程序的 ErrorController。
  • 将 debug_print_backtrace 函数的调用放在 init 方法的顶部(可选用 die())

回答by piyush

Open urproject/application/config and open application.ini
Change the second line:

打开urproject/application/config,打开application.ini
更改第二行:

phpSettings.display_errors = 0 

to

phpSettings.display_errors = 1

Now it will display errors.

现在它会显示错误。

回答by grasshopper

For anybody for whom the answers given here didn't work, one can always go to the apache logs to see a description of the problem. It would of course be more convenient if this showed on the page, but I find it to be an acceptable alternative.

对于此处给出的答案不起作用的任何人,可以随时访问 apache 日志以查看问题的描述。如果这显示在页面上当然会更方便,但我发现这是一个可以接受的选择。

 /var/log/apache2/error.log

I have this file open with vim and type :e to refresh and G to go to the bottom of the page to see the most recent error when I get the blank page. It tells you the time the error occurred, the message and the line, so it's pretty helpful.

我用vim打开了这个文件,输入:e刷新,输入G到页面底部,当我得到空白页时查看最近的错误。它会告诉您错误发生的时间、消息和行,因此非常有用。

回答by Prabhagaran

put these lines in application/configs/config.php

将这些行放在 application/configs/config.php 中

error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 'on');