为了系统的平稳运行,需要有效处理系统故障。Zend Framework带有默认错误陷阱,该陷阱会在错误发生时进行打印和记录。此错误处理程序用于捕获Exception。
当调试为true时,错误处理程序将显示错误,而当调试为false时,错误处理程序将记录错误。Zend Framework具有几个异常类,并且内置的异常处理将捕获任何未捕获的异常并呈现一个有用的页面。
默认错误处理
我们可以在应用程序配置文件myapp / module / Application / config / module.config.php中配置默认错误设置。
部分代码示例如下:
'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',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
],
'template_path_stack' => [
__DIR__ . '/../view',
],
], 在此,display_exception,not_found_template,exception_template,error / 404和error / index是与错误相关的配置项,它们是不言自明的。
其中最重要的项目是error / index。这是系统中发生异常时显示的模板。我们可以修改此模板myapp / module / Application / view / error / index.phtml以控制要显示的错误数量。
作者:terry,如若转载,请注明出处:https://www.web176.com/zendframework/259.html
支付宝
微信