Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display exception errors thrown by Zend framework?

I am working with Zend framework and just hate the fact that I seem to encounter hundreds of exception errors like if I try to reference a non existant property of an object my application just dies and crashes. However I have no idea where to see these errors or how to be able to display them on screen. I've set display errors to true and error reporting to E_ALL but when an error is thrown all I see is a blank page rendered only until a bit before where the error apparently occurred or the exception was thrown.

like image 643
Ali Avatar asked May 02 '10 10:05

Ali


3 Answers

What's the value of the APPLICATION_ENV environment variable.

The standard public/index.php in a ZF application does the following:

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

This means that if no APPLICATION_ENV is set, the environment is set as "production". If you look at your application.ini file, you'll see that the framework suppresses errors if the environment is production.

Of course, you're developing, so you want to use the 'development' environment.

If you're running under Apache/mod_php, you can set this in your httpd.conf, or an .htaccess file:

SetEnv APPLICATION_ENV development

Or you could always get ugly and hack away at your public/index.php:

// Define application environment

/*defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));*/

// Ugly hack because I'm too lazy to properly set up my environment.
define('APPLICATION_ENV','development');
like image 196
timdev Avatar answered Nov 15 '22 22:11

timdev


If you create an application skeleton with Zend Tool, you'll typically have an error controller which will catch runtime errors and display them. You'll want to follow timdev's advice to SetEnv APPLICATION_ENV development and then, in your application/configs/application.ini:

[development : production]

; This section defines config parameters loaded when the APPLICATION_ENV directive
; is set to 'development' - undefined parameters are inherited from the production
; section.

; show errors and exceptions during development
 phpSettings.display_startup_errors = 1
 phpSettings.display_errors = 1
 resources.frontController.params.displayExceptions = 1
like image 22
jah Avatar answered Nov 15 '22 22:11

jah


Referencing a non-existant property is an error in PHP, not an Exception. Errors are generally in the output of the html if you enable display_errors in your php.ini. But beware: they can as well occur within an invisible html tag like:

<div style="display:none"><? echo $object->nonexistant?> ...

... so you need to check the HTML output of your page (CTRL-U in firefox) and scroll to the bottom

like image 26
soulmerge Avatar answered Nov 15 '22 21:11

soulmerge