Categories: Zend framework教程

Zend框架-错误处理

为了系统的平稳运行,需要有效处理系统故障。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

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

4 天 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

2 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

2 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

2 周 ago

聊聊React和Vue组件更新的实现及区别

React 和 Vue 都是当…

3 周 ago