English 中文(简体)
Zend Framework - Error Handling
  • 时间:2024-09-17

Zend Framework - Error Handpng


Previous Page Next Page  

Failure of system needs to be handled effectively for the smooth running of the system. Zend Framework comes with a default error trapping that prints and logs the error as they occur. This same error handler is used to catch Exceptions.

The Error Handler displays errors when the debug is true and logs the error when the debug is false. Zend Framework has several exception classes and the built-in exception handpng will capture any uncaught exception and render a useful page.

Default Error Handpng

We can configure the default error settings in the apppcation configuration file, myapp/module/Apppcation/config/module.config.php.

The partial code sample is as follows −

 view_manager  => [ 
    display_not_found_reason  => true, 
    display_exceptions        => true, 
    doctype                   =>  HTML5 , 
    not_found_template        =>  error/404 , 
    exception_template        =>  error/index , 
    template_map  => [ 
       layout/layout            => __DIR__ .  /../view/layout/layout.phtml , 
       apppcation/index/index  => __DIR__ .  /../view/apppcation/index/index.phtml , 
       error/404                => __DIR__ .  /../view/error/404.phtml , 
       error/index              => __DIR__ .  /../view/error/index.phtml , 
   ], 
    template_path_stack  => [ 
      __DIR__ .  /../view , 
   ], 
], 

Here, the display_exception, not_found_template, exception_template, error/404 and the error/index are error related configuration items and are self-explanatory.

The most important item among these is the error/index. This is the template shown when an exception occurs in the system. We can modify this template, myapp/module/Apppcation/view/error/index.phtml to control the amount of error to be shown.

Advertisements