Display php errors when using Zend framework

2019-01-17 03:30发布

问题:

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.

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.

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.

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.

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

回答1:

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

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:

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

To allow failed include/require statements to be issued.



回答2:

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

resources.frontController.params.displayExceptions = 0

To:

resources.frontController.params.displayExceptions = 1

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



回答3:

Set this in your config:

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


回答4:

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

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



回答5:

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..

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


回答6:

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

phpSettings.display_errors = 0 

to

phpSettings.display_errors = 1

Now it will display errors.



回答7:

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

  • find ErrorController of your application.
  • put the call of debug_print_backtrace function at the top of init method (with die() optionally)


回答8:

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.

 /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.



回答9:

put these lines in application/configs/config.php

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