CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 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

Namespaces

  • Global
  • Cake
    • AttributeResolver
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
      • Debug
      • Middleware
      • Renderer
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class WebExceptionRenderer

Web Exception Renderer.

Captures and handles all unhandled exceptions. Displays helpful framework errors when debug is true. When debug is false, WebExceptionRenderer will render 404 or 500 errors. If an uncaught exception is thrown and it is a type that WebExceptionHandler does not know about it will be treated as a 500 error.

Implementing application specific exception rendering

You can implement application specific exception handling by creating a subclass of WebExceptionRenderer and configure it to be the exceptionRenderer in config/error.php

Using a subclass of WebExceptionRenderer

Using a subclass of WebExceptionRenderer gives you full control over how Exceptions are rendered, you can configure your class in your config/app.php.

Namespace: Cake\Error\Renderer

Property Summary

  • $controller protected
    Cake\Controller\Controller

    Controller instance.

  • $method protected
    string

    The method corresponding to the Exception this object is for.

  • $template protected
    string

    Template to render for {@link \Cake\Core\Exception\CakeException}

Method Summary

  • __construct() public

    Creates the controller to perform rendering on the error response.

  • __debugInfo() public

    Returns an array that can be used to describe the internal state of this object.

  • clearOutput() protected

    Clear output buffers so error pages display properly.

  • customMethod() protected

    Render a custom error method/template.

  • getController() protected

    Get the controller instance to handle the exception. Override this method in subclasses to customize the controller used. This method returns the built in ErrorController normally, or if an error is repeated a bare controller will be used.

  • getHttpCode() protected

    Gets the appropriate http status code for exception.

  • message() protected

    Get error message.

  • method() protected

    Get method name

  • outputMessage() protected

    Generate the response using the controller object.

  • outputMessageSafe() protected

    A safer way to render error messages, replaces all helpers, with basics and doesn't call component methods.

  • render() public

    Renders the response for the exception.

  • shutdown() protected

    Run the shutdown events.

    Triggers the afterFilter and afterDispatch events.

  • template() protected

    Get template for rendering exception info.

  • write() public

    Emit the response content

Method Detail

__construct() ¶ public

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

Creates the controller to perform rendering on the error response.

Parameters
Throwable $error

Exception.

Cake\Http\ServerRequest|null $request optional

If set, this request will be used to create the controller that will render the error.

__debugInfo() ¶ public

__debugInfo(): array<string, mixed>

Returns an array that can be used to describe the internal state of this object.

Returns
array<string, mixed>

clearOutput() ¶ protected

clearOutput(): void

Clear output buffers so error pages display properly.

Returns
void

customMethod() ¶ protected

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

Render a custom error method/template.

Parameters
string $method

The method name to invoke.

Throwable $exception

The exception to render.

Returns
Cake\Http\Response

The response to send.

getController() ¶ protected

getController(): Cake\Controller\Controller

Get the controller instance to handle the exception. Override this method in subclasses to customize the controller used. This method returns the built in ErrorController normally, or if an error is repeated a bare controller will be used.

Returns
Cake\Controller\Controller

getHttpCode() ¶ protected

getHttpCode(Throwable $exception): int

Gets the appropriate http status code for exception.

Parameters
Throwable $exception

Exception.

Returns
int

A valid HTTP status code.

message() ¶ protected

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

Get error message.

Parameters
Throwable $exception

Exception.

int $code

Error code.

Returns
string

Error message

method() ¶ protected

method(Throwable $exception): string

Get method name

Parameters
Throwable $exception

Exception instance.

Returns
string

outputMessage() ¶ protected

outputMessage(string $template, bool $skipControllerCheck = false): Cake\Http\Response

Generate the response using the controller object.

Parameters
string $template

The template to render.

bool $skipControllerCheck optional

Skip checking controller for existence of method matching the exception name.

Returns
Cake\Http\Response

A response object that can be sent.

outputMessageSafe() ¶ protected

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

A safer way to render error messages, replaces all helpers, with basics and doesn't call component methods.

Parameters
string $template

The template to render.

Returns
Cake\Http\Response

A response object that can be sent.

render() ¶ public

render(): Psr\Http\Message\ResponseInterface

Renders the response for the exception.

Returns
Psr\Http\Message\ResponseInterface

The response to be sent.

shutdown() ¶ protected

shutdown(): Cake\Http\Response

Run the shutdown events.

Triggers the afterFilter and afterDispatch events.

Returns
Cake\Http\Response

The response to serve.

template() ¶ protected

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

Get template for rendering exception info.

Parameters
Throwable $exception

Exception instance.

string $method

Method name.

int $code

Error code.

Returns
string

Template name

write() ¶ public

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

Emit the response content

Parameters
Psr\Http\Message\ResponseInterface|string $output

The response to output.

Returns
void

Property Detail

$controller ¶ protected

Controller instance.

Type
Cake\Controller\Controller

$method ¶ protected

The method corresponding to the Exception this object is for.

Type
string

$template ¶ protected

Template to render for {@link \Cake\Core\Exception\CakeException}

Type
string
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs