CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 业务解决方案
  • 商品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (Github)
    • 面包店
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 新闻通讯
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • 帮助与支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

命名空间

  • 全局
  • Cake
    • 缓存
    • 集合
    • 命令
    • 控制台
    • 控制器
    • 核心
    • 数据库
    • 数据源
    • 错误
      • 调试
      • 中间件
      • 渲染器
    • 事件
    • 表单
    • HTTP
    • 国际化
    • 日志
    • 邮件
    • 网络
    • ORM
    • 路由
    • 测试套件
    • 实用工具
    • 验证
    • 视图

类 WebExceptionRenderer

Web 异常渲染器。

捕获并处理所有未处理的异常。当调试为 true 时,显示有用的框架错误。当调试为 false 时,WebExceptionRenderer 将渲染 404 或 500 错误。如果抛出未捕获的异常,并且它属于 WebExceptionHandler 不认识的类型,则将其视为 500 错误。

实现应用程序特定的异常渲染

您可以通过创建 WebExceptionRenderer 的子类并将其配置为 config/error.php 中的 exceptionRenderer 来实现应用程序特定的异常处理。

使用 WebExceptionRenderer 的子类

使用 WebExceptionRenderer 的子类可以让您完全控制异常的渲染方式,您可以在 config/app.php 中配置您的类。

命名空间: Cake\Error\Renderer

属性摘要

  • $controller protected
    Cake\Controller\Controller

    控制器实例。

  • $error protected
    Throwable

    正在处理的异常。

  • $exceptionHttpCodes protected
    array<string, int>

    异常到 http 状态码的映射。

  • $method protected
    string

    与该对象所针对的异常相对应的函数名。

  • $request protected
    Cake\Http\ServerRequest|null

    如果设置,这将是用于创建将渲染错误的控制器的请求。

  • $template protected
    string

    用于渲染 {@link \Cake\Core\Exception\CakeException} 的模板

方法摘要

  • __construct() public

    创建控制器以对错误响应执行渲染。

  • __debugInfo() public

    返回一个数组,可用于描述此对象的内部状态。

  • _customMethod() protected

    渲染自定义错误函数名/模板。

  • _getController() protected

    获取处理异常的控制器实例。在子类中覆盖此函数名以自定义使用的控制器。此函数名通常返回内置的 ErrorController,或者如果错误重复,则将使用一个空的控制器。

  • _message() protected

    获取错误消息。

  • _method() protected

    获取函数名。

  • _outputMessage() protected

    使用控制器对象生成响应。

  • _outputMessageSafe() protected

    一种更安全的渲染错误消息的方法,用基本方法替换所有帮助器,并且不调用组件函数名。

  • _shutdown() protected

    运行关闭事件。

  • _template() protected

    获取用于渲染异常信息的模板。

  • clearOutput() protected

    清除输出缓冲区,以便错误页面正确显示。

  • getHttpCode() protected

    获取异常的适当 http 状态码。

  • render() public

    渲染异常的响应。

  • write() public

    发出响应内容

方法详情

__construct() ¶ public

__construct(Throwable $exception, Cake\Http\ServerRequest|null $request = null)

创建控制器以对错误响应执行渲染。

参数
Throwable $exception

异常。

Cake\Http\ServerRequest|null $request 可选

请求,如果设置,它将用于代替创建一个新的请求。

__debugInfo() ¶ public

__debugInfo(): array<string, mixed>

返回一个数组,可用于描述此对象的内部状态。

返回值
array<string, mixed>

_customMethod() ¶ protected

_customMethod(string $method, Throwable $exception): Cake\Http\Response

渲染自定义错误函数名/模板。

参数
string $method

要调用的函数名。

Throwable $exception

要渲染的异常。

返回值
Cake\Http\Response

_getController() ¶ protected

_getController(): Cake\Controller\Controller

获取处理异常的控制器实例。在子类中覆盖此函数名以自定义使用的控制器。此函数名通常返回内置的 ErrorController,或者如果错误重复,则将使用一个空的控制器。

返回值
Cake\Controller\Controller

_message() ¶ protected

_message(Throwable $exception, int $code): string

获取错误消息。

参数
Throwable $exception

异常。

int $code

错误代码。

返回值
string

_method() ¶ protected

_method(Throwable $exception): string

获取函数名。

参数
Throwable $exception

异常实例。

返回值
string

_outputMessage() ¶ protected

_outputMessage(string $template): Cake\Http\Response

使用控制器对象生成响应。

参数
string $template

要渲染的模板。

返回值
Cake\Http\Response

_outputMessageSafe() ¶ protected

_outputMessageSafe(string $template): Cake\Http\Response

一种更安全的渲染错误消息的方法,用基本方法替换所有帮助器,并且不调用组件函数名。

参数
string $template

要渲染的模板。

返回值
Cake\Http\Response

_shutdown() ¶ protected

_shutdown(): Cake\Http\Response

运行关闭事件。

触发 afterFilter 和 afterDispatch 事件。

返回值
Cake\Http\Response

_template() ¶ protected

_template(Throwable $exception, string $method, int $code): string

获取用于渲染异常信息的模板。

参数
Throwable $exception

异常实例。

string $method

函数名。

int $code

错误代码。

返回值
string

clearOutput() ¶ protected

clearOutput(): void

清除输出缓冲区,以便错误页面正确显示。

返回值
void

getHttpCode() ¶ protected

getHttpCode(Throwable $exception): int

获取异常的适当 http 状态码。

参数
Throwable $exception

异常。

返回值
int

render() ¶ public

render(): Cake\Http\Response

渲染异常的响应。

返回值
Cake\Http\Response

write() ¶ public

write(Psr\Http\Message\ResponseInterface|string $output): void

发出响应内容

此函数名仅在全局默认异常处理程序处理异常时调用。

参数
Psr\Http\Message\ResponseInterface|string $output

要输出的响应。

返回值
void

属性详情

$controller ¶ protected

控制器实例。

类型
Cake\Controller\Controller

$error ¶ protected

正在处理的异常。

类型
Throwable

$exceptionHttpCodes ¶ protected

异常到 http 状态码的映射。

对于不想让特定异常抛出 404 错误或希望自动转换应用程序异常的用户,可以自定义它。

类型
array<string, int>

$method ¶ protected

与该对象所针对的异常相对应的函数名。

类型
string

$request ¶ protected

如果设置,这将是用于创建将渲染错误的控制器的请求。

类型
Cake\Http\ServerRequest|null

$template ¶ protected

用于渲染 {@link \Cake\Core\Exception\CakeException} 的模板

类型
string
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题 (Github)
  • 面包店
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 新闻通讯
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助与支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成