A free and open-source book on Zend Framework for beginners


4.18. Error Pages

When a page could not be found or some other error happens inside of your web application, a standard error page is displayed. The appearance of the error page is controlled by the error templates. There are two error templates: error/404 which is used for "404 Page Not Found" error (shown in figure 4.10), and error/index which is displayed when a generic error occurs (such as an unhandled exception is thrown somewhere inside of the application).

Figure 4.10. 404 Error Page Figure 4.10. 404 Error Page

The module.config.php file contains several parameters under the view_manager key, which you can use to configure the appearance of your error templates:

<?php
return [
    //...
    
    'view_manager' => [    
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        //...
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',    
        'template_map' => [
            //...
            'error/404' => __DIR__ . '/../view/error/404.phtml',
            'error/index'=> __DIR__ . '/../view/error/index.phtml',
        ],
        //...
    ],
];

You typically set the display_not_found_reason and display_exceptions parameters to false in production systems, because you don't want site visitors see the details about errors in your site. However, you will still be able to retrieve the detailed information from Apache's error.log file.


Top