Class ErrorController
Error Handling Controller
Controller used by ErrorHandler to render error views.
Property Summary
- 
        $Flash public @propertyCake\Controller\Component\FlashComponent
- 
        $FormProtection public @propertyCake\Controller\Component\FormProtectionComponent
- 
        $Paginator public @propertyCake\Controller\Component\PaginatorComponent
- 
        $RequestHandler public @propertyCake\Controller\Component\RequestHandlerComponent
- 
        $_components protectedCake\Controller\ComponentRegistryInstance of ComponentRegistry used to create Components 
- 
        $_eventClass protectedstringDefault class name for new event objects. 
- 
        $_eventManager protectedCake\Event\EventManagerInterfaceInstance of the Cake\Event\EventManager this object is using to dispatch inner events. 
- 
        $_modelFactories protectedarrayA list of overridden model factory functions. 
- 
        $_modelType protectedstringThe model type to use. 
- 
        $_responseClass protectedstringThe class name to use for creating the response object. 
- 
        $_tableLocator protectedCake\ORM\Locator\LocatorInterface|nullTable locator instance 
- 
        $_viewBuilder protectedCake\View\ViewBuilder|nullThe view builder instance being used. 
- 
        $autoRender protectedboolSet to true to automatically render the view after action logic. 
- 
        $modelClass protectedstring|nullThis object's primary model class name. Should be a plural form. CakePHP will not inflect the name. 
- 
        $name protectedstringThe name of this controller. Controller names are plural, named after the model they manipulate. 
- 
        $paginate publicarraySettings for pagination. 
- 
        $plugin protectedstring|nullAutomatically set to the name of a plugin. 
- 
        $request protectedCake\Http\ServerRequestAn instance of a \Cake\Http\ServerRequest object that contains information about the current request. This object contains all the information about a request and several methods for reading additional information about the request. 
- 
        $response protectedCake\Http\ResponseAn instance of a Response object that contains information about the impending response 
Method Summary
- 
          __construct() publicConstructor. 
- 
          __get() publicMagic accessor for model autoloading. 
- 
          __set() publicMagic setter for removed properties. 
- 
          _setModelClass() protectedSet the modelClass property based on conventions. 
- 
          _templatePath() protectedGet the templatePath based on controller name and request prefix. 
- 
          afterFilter() publicCalled after the controller action is run and rendered. 
- 
          beforeFilter() publicCalled before the controller action. You can use this method to configure and customize components or perform logic that needs to happen before each controller action. 
- 
          beforeRedirect() publicThe beforeRedirect method is invoked when the controller's redirect method is called but before any further action. 
- 
          beforeRender() publicbeforeRender callback. 
- 
          components() publicGet the component registry for this controller. 
- 
          createView() publicConstructs the view class instance based on the current configuration. 
- 
          disableAutoRender() publicDisable automatic action rendering. 
- 
          dispatchEvent() publicWrapper for creating and dispatching events. 
- 
          enableAutoRender() publicEnable automatic action rendering. 
- 
          getAction() publicGet the closure for action to be invoked by ControllerFactory. 
- 
          getEventManager() publicReturns the Cake\Event\EventManager manager instance for this object. 
- 
          getModelType() publicGet the model type to be used by this class 
- 
          getName() publicReturns the controller name. 
- 
          getPlugin() publicReturns the plugin name. 
- 
          getRequest() publicGets the request instance. 
- 
          getResponse() publicGets the response instance. 
- 
          getTableLocator() publicGets the table locator. 
- 
          implementedEvents() publicReturns a list of all events that will fire in the controller during its lifecycle. You can override this function to add your own listener callbacks 
- 
          initialize() publicInitialization hook method. 
- 
          invokeAction() publicDispatches the controller action. 
- 
          isAction() publicMethod to check that an action is accessible from a URL. 
- 
          isAutoRenderEnabled() publicReturns true if an action should be rendered automatically. 
- 
          loadComponent() publicAdd a component to the controller's registry. 
- 
          loadModel() publicLoads and constructs repository objects required by this object 
- 
          log() publicConvenience method to write a message to Log. See Log::write() for more information on writing to logs. 
- 
          modelFactory() publicOverride a existing callable to generate repositories of a given type. 
- 
          paginate() publicHandles pagination of records in Table objects. 
- 
          redirect() publicRedirects to given $url, after turning off $this->autoRender. 
- 
          referer() publicReturns the referring URL for this request. 
- 
          render() publicInstantiates the correct view class, hands it its data, and uses it to render the view output. 
- 
          set() publicSaves a variable or an associative array of variables for use inside a template. 
- 
          setAction() publicInternally redirects one action to another. Does not perform another HTTP request unlike Controller::redirect() 
- 
          setEventManager() publicReturns the Cake\Event\EventManagerInterface instance for this object. 
- 
          setModelType() publicSet the model type to be used by this class 
- 
          setName() publicSets the controller name. 
- 
          setPlugin() publicSets the plugin name. 
- 
          setRequest() publicSets the request objects and configures a number of controller properties based on the contents of the request. Controller acts as a proxy for certain View variables which must also be updated here. The properties that get set are: 
- 
          setResponse() publicSets the response instance. 
- 
          setTableLocator() publicSets the table locator. 
- 
          shutdownProcess() publicPerform the various shutdown processes for this controller. Fire the Components and Controller callbacks in the correct order. 
- 
          startupProcess() publicPerform the startup process for this controller. Fire the Components and Controller callbacks in the correct order. 
- 
          viewBuilder() publicGet the view builder being used. 
Method Detail
__construct() ¶ public
__construct(Cake\Http\ServerRequest|null $request = null, Cake\Http\Response|null $response = null, string|null $name = null, Cake\Event\EventManagerInterface|null $eventManager = null, Cake\Controller\ComponentRegistry|null $components = null)Constructor.
Sets a number of properties based on conventions if they are empty. To override the conventions CakePHP uses you can define properties in your class declaration.
Parameters
- 
                Cake\Http\ServerRequest|null$request optional
- Request object for this controller. Can be null for testing, but expect that features that use the request parameters will not work. 
- 
                Cake\Http\Response|null$response optional
- Response object for this controller. 
- 
                string|null$name optional
- Override the name useful in testing when using mocks. 
- 
                Cake\Event\EventManagerInterface|null$eventManager optional
- The event manager. Defaults to a new instance. 
- 
                Cake\Controller\ComponentRegistry|null$components optional
- The component registry. Defaults to a new instance. 
__get() ¶ public
__get(string $name): Cake\Datasource\RepositoryInterface|nullMagic accessor for model autoloading.
Parameters
- 
                string$name
- Property name 
Returns
Cake\Datasource\RepositoryInterface|nullThe model instance or null
__set() ¶ public
__set(string $name, mixed $value): voidMagic setter for removed properties.
Parameters
- 
                string$name
- Property name. 
- 
                mixed$value
- Value to set. 
Returns
void_setModelClass() ¶ protected
_setModelClass(string $name): voidSet the modelClass property based on conventions.
If the property is already set it will not be overwritten
Parameters
- 
                string$name
- Class name. 
Returns
void_templatePath() ¶ protected
_templatePath(): stringGet the templatePath based on controller name and request prefix.
Returns
stringafterFilter() ¶ public
afterFilter(Cake\Event\EventInterface $event): Cake\Http\Response|null|voidCalled after the controller action is run and rendered.
Parameters
- 
                Cake\Event\EventInterface$event
- An Event instance 
Returns
Cake\Http\Response|null|voidLinks
beforeFilter() ¶ public
beforeFilter(Cake\Event\EventInterface $event): Cake\Http\Response|null|voidCalled before the controller action. You can use this method to configure and customize components or perform logic that needs to happen before each controller action.
Parameters
- 
                Cake\Event\EventInterface$event
- An Event instance 
Returns
Cake\Http\Response|null|voidLinks
beforeRedirect() ¶ public
beforeRedirect(Cake\Event\EventInterface $event, string|array $url, Cake\Http\Response $response): Cake\Http\Response|null|voidThe beforeRedirect method is invoked when the controller's redirect method is called but before any further action.
If the event is stopped the controller will not continue on to redirect the request. The $url and $status variables have same meaning as for the controller's method. You can set the event result to response instance or modify the redirect location using controller's response instance.
Parameters
- 
                Cake\Event\EventInterface$event
- An Event instance 
- 
                string|array$url
- A string or array-based URL pointing to another location within the app, or an absolute URL 
- 
                Cake\Http\Response$response
- The response object. 
Returns
Cake\Http\Response|null|voidLinks
beforeRender() ¶ public
beforeRender(Cake\Event\EventInterface $event): Cake\Http\Response|null|voidbeforeRender callback.
Parameters
- 
                Cake\Event\EventInterface$event
- Event. 
Returns
Cake\Http\Response|null|voidcomponents() ¶ public
components(Cake\Controller\ComponentRegistry|null $components = null): Cake\Controller\ComponentRegistryGet the component registry for this controller.
If called with the first parameter, it will be set as the controller $this->_components property
Parameters
- 
                Cake\Controller\ComponentRegistry|null$components optional
- Component registry. 
Returns
Cake\Controller\ComponentRegistrycreateView() ¶ public
createView(string|null $viewClass = null): Cake\View\ViewConstructs the view class instance based on the current configuration.
Parameters
- 
                string|null$viewClass optional
- Optional namespaced class name of the View class to instantiate. 
Returns
Cake\View\ViewThrows
Cake\View\Exception\MissingViewExceptionIf view class was not found.
disableAutoRender() ¶ public
disableAutoRender(): $thisDisable automatic action rendering.
Returns
$thisdispatchEvent() ¶ public
dispatchEvent(string $name, array|null $data = null, object|null $subject = null): Cake\Event\EventInterfaceWrapper for creating and dispatching events.
Returns a dispatched event.
Parameters
- 
                string$name
- Name of the event. 
- 
                array|null$data optional
- Any value you wish to be transported with this event to it can be read by listeners. 
- 
                object|null$subject optional
- The object that this event applies to ($this by default). 
Returns
Cake\Event\EventInterfaceenableAutoRender() ¶ public
enableAutoRender(): $thisEnable automatic action rendering.
Returns
$thisgetAction() ¶ public
getAction(): ClosureGet the closure for action to be invoked by ControllerFactory.
Returns
ClosureThrows
Cake\Controller\Exception\MissingActionExceptiongetEventManager() ¶ public
getEventManager(): Cake\Event\EventManagerInterfaceReturns the Cake\Event\EventManager manager instance for this object.
You can use this instance to register any new listeners or callbacks to the object events, or create your own events and trigger them at will.
Returns
Cake\Event\EventManagerInterfacegetModelType() ¶ public
getModelType(): stringGet the model type to be used by this class
Returns
stringgetRequest() ¶ public
getRequest(): Cake\Http\ServerRequestGets the request instance.
Returns
Cake\Http\ServerRequestgetResponse() ¶ public
getResponse(): Cake\Http\ResponseGets the response instance.
Returns
Cake\Http\ResponsegetTableLocator() ¶ public
getTableLocator(): Cake\ORM\Locator\LocatorInterfaceGets the table locator.
Returns
Cake\ORM\Locator\LocatorInterfaceimplementedEvents() ¶ public
implementedEvents(): arrayReturns a list of all events that will fire in the controller during its lifecycle. You can override this function to add your own listener callbacks
Example:
 public function implementedEvents()
 {
     return [
         'Order.complete' => 'sendEmail',
         'Article.afterBuy' => 'decrementInventory',
         'User.onRegister' => ['callable' => 'logRegistration', 'priority' => 20, 'passParams' => true]
     ];
 }Returns
arrayinitialize() ¶ public
initialize(): voidInitialization hook method.
Implement this method to avoid having to overwrite the constructor and call parent.
Returns
voidinvokeAction() ¶ public
invokeAction(Closure $action, array $args): voidDispatches the controller action.
Parameters
- 
                Closure$action
- The action closure. 
- 
                array$args
- The arguments to be passed when invoking action. 
Returns
voidThrows
UnexpectedValueExceptionIf return value of action is not `null` or `ResponseInterface` instance.
isAction() ¶ public
isAction(string $action): boolMethod to check that an action is accessible from a URL.
Override this method to change which controller methods can be reached. The default implementation disallows access to all methods defined on Cake\Controller\Controller, and allows all public methods on all subclasses of this class.
Parameters
- 
                string$action
- The action to check. 
Returns
boolWhether or not the method is accessible from a URL.
Throws
ReflectionExceptionisAutoRenderEnabled() ¶ public
isAutoRenderEnabled(): boolReturns true if an action should be rendered automatically.
Returns
boolloadComponent() ¶ public
loadComponent(string $name, array $config = []): Cake\Controller\ComponentAdd a component to the controller's registry.
This method will also set the component to a property. For example:
$this->loadComponent('Acl.Acl');Will result in a Toolbar property being set.
Parameters
- 
                string$name
- The name of the component to load. 
- 
                array$config optional
- The config for the component. 
Returns
Cake\Controller\ComponentThrows
ExceptionloadModel() ¶ public
loadModel(string|null $modelClass = null, string|null $modelType = null): Cake\Datasource\RepositoryInterfaceLoads and constructs repository objects required by this object
Typically used to load ORM Table objects as required. Can also be used to load other types of repository objects your application uses.
If a repository provider does not return an object a MissingModelException will be thrown.
Parameters
- 
                string|null$modelClass optional
- Name of model class to load. Defaults to $this->modelClass. The name can be an alias like - 'Post'or FQCN like- App\Model\Table\PostsTable::class.
- 
                string|null$modelType optional
- The type of repository to load. Defaults to the getModelType() value. 
Returns
Cake\Datasource\RepositoryInterfaceThe model instance created.
Throws
Cake\Datasource\Exception\MissingModelExceptionIf the model class cannot be found.
UnexpectedValueExceptionIf $modelClass argument is not provided and ModelAwareTrait::$modelClass property value is empty.
log() ¶ public
log(string $message, int|string $level = LogLevel::ERROR, string|array $context = []): boolConvenience method to write a message to Log. See Log::write() for more information on writing to logs.
Parameters
- 
                string$message
- Log message. 
- 
                int|string$level optional
- Error level. 
- 
                string|array$context optional
- Additional log data relevant to this message. 
Returns
boolSuccess of log write.
modelFactory() ¶ public
modelFactory(string $type, callable $factory): voidOverride a existing callable to generate repositories of a given type.
Parameters
- 
                string$type
- The name of the repository type the factory function is for. 
- 
                callable$factory
- The factory function used to create instances. 
Returns
voidpaginate() ¶ public
paginate(Cake\ORM\Table|string|Cake\ORM\Query|null $object = null, array $settings = []): Cake\ORM\ResultSet|Cake\Datasource\ResultSetInterfaceHandles pagination of records in Table objects.
Will load the referenced Table object, and have the PaginatorComponent
paginate the query using the request date and settings defined in $this->paginate.
This method will also make the PaginatorHelper available in the view.
Parameters
- 
                Cake\ORM\Table|string|Cake\ORM\Query|null$object optional
- Table to paginate (e.g: Table instance, 'TableName' or a Query object) 
- 
                array$settings optional
- The settings/configuration used for pagination. 
Returns
Cake\ORM\ResultSet|Cake\Datasource\ResultSetInterfaceQuery results
Throws
RuntimeExceptionWhen no compatible table object can be found.
Links
redirect() ¶ public
redirect(string|array|Psr\Http\Message\UriInterface $url, int $status = 302): Cake\Http\Response|nullRedirects to given $url, after turning off $this->autoRender.
Parameters
- 
                string|array|Psr\Http\Message\UriInterface$url
- A string, array-based URL or UriInterface instance. 
- 
                int$status optional
- HTTP status code. Defaults to - 302.
Returns
Cake\Http\Response|nullLinks
referer() ¶ public
referer(string|array|null $default = '/', bool $local = true): stringReturns the referring URL for this request.
Parameters
- 
                string|array|null$default optional
- Default URL to use if HTTP_REFERER cannot be read from headers 
- 
                bool$local optional
- If false, do not restrict referring URLs to local server. Careful with trusting external sources. 
Returns
stringReferring URL
render() ¶ public
render(string|null $template = null, string|null $layout = null): Cake\Http\ResponseInstantiates the correct view class, hands it its data, and uses it to render the view output.
Parameters
- 
                string|null$template optional
- Template to use for rendering 
- 
                string|null$layout optional
- Layout to use 
Returns
Cake\Http\ResponseA response object containing the rendered view.
Links
set() ¶ public
set(string|array $name, mixed $value = null): $thisSaves a variable or an associative array of variables for use inside a template.
Parameters
- 
                string|array$name
- A string or an array of data. 
- 
                mixed$value optional
- Value in case $name is a string (which then works as the key). Unused if $name is an associative array, otherwise serves as the values to $name's keys. 
Returns
$thissetAction() ¶ public
setAction(string $action, mixed ...$args): mixedInternally redirects one action to another. Does not perform another HTTP request unlike Controller::redirect()
Examples:
setAction('another_action');
setAction('action_with_parameters', $parameter1);Parameters
- 
                string$action
- The new action to be 'redirected' to. Any other parameters passed to this method will be passed as parameters to the new action. 
- 
                mixed...$args
- Arguments passed to the action 
Returns
mixedReturns the return value of the called action
setEventManager() ¶ public
setEventManager(Cake\Event\EventManagerInterface $eventManager): $thisReturns the Cake\Event\EventManagerInterface instance for this object.
You can use this instance to register any new listeners or callbacks to the object events, or create your own events and trigger them at will.
Parameters
- 
                Cake\Event\EventManagerInterface$eventManager
- the eventManager to set 
Returns
$thissetModelType() ¶ public
setModelType(string $modelType): $thisSet the model type to be used by this class
Parameters
- 
                string$modelType
- The model type 
Returns
$thissetName() ¶ public
setName(string $name): $thisSets the controller name.
Parameters
- 
                string$name
- Controller name. 
Returns
$thissetPlugin() ¶ public
setPlugin(string|null $name): $thisSets the plugin name.
Parameters
- 
                string|null$name
- Plugin name. 
Returns
$thissetRequest() ¶ public
setRequest(Cake\Http\ServerRequest $request): $thisSets the request objects and configures a number of controller properties based on the contents of the request. Controller acts as a proxy for certain View variables which must also be updated here. The properties that get set are:
- $this->request - To the $request parameter
Parameters
- 
                Cake\Http\ServerRequest$request
- Request instance. 
Returns
$thissetResponse() ¶ public
setResponse(Cake\Http\Response $response): $thisSets the response instance.
Parameters
- 
                Cake\Http\Response$response
- Response instance. 
Returns
$thissetTableLocator() ¶ public
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $thisSets the table locator.
Parameters
- 
                Cake\ORM\Locator\LocatorInterface$tableLocator
- LocatorInterface instance. 
Returns
$thisshutdownProcess() ¶ public
shutdownProcess(): Psr\Http\Message\ResponseInterface|nullPerform the various shutdown processes for this controller. Fire the Components and Controller callbacks in the correct order.
- triggers the component shutdowncallback.
- calls the Controller's afterFiltermethod.
Returns
Psr\Http\Message\ResponseInterface|nullstartupProcess() ¶ public
startupProcess(): Psr\Http\Message\ResponseInterface|nullPerform the startup process for this controller. Fire the Components and Controller callbacks in the correct order.
- Initializes components, which fires their initializecallback
- Calls the controller beforeFilter.
- triggers Component startupmethods.
Returns
Psr\Http\Message\ResponseInterface|nullviewBuilder() ¶ public
viewBuilder(): Cake\View\ViewBuilderGet the view builder being used.
Returns
Cake\View\ViewBuilderProperty Detail
$_components ¶ protected
Instance of ComponentRegistry used to create Components
Type
Cake\Controller\ComponentRegistry$_eventManager ¶ protected
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
Type
Cake\Event\EventManagerInterface$modelClass ¶ protected
This object's primary model class name. Should be a plural form. CakePHP will not inflect the name.
Example: For an object named 'Comments', the modelClass would be 'Comments'.
Plugin classes should use Plugin.Comments style names to correctly load
models from the correct plugin.
Use empty string to not use auto-loading on this object. Null auto-detects based on controller name.
Type
string|null$name ¶ protected
The name of this controller. Controller names are plural, named after the model they manipulate.
Set automatically using conventions in Controller::__construct().
Type
string$paginate ¶ public
Settings for pagination.
Used to pre-configure pagination preferences for the various tables your controller will be paginating.
Type
array$request ¶ protected
An instance of a \Cake\Http\ServerRequest object that contains information about the current request. This object contains all the information about a request and several methods for reading additional information about the request.
Type
Cake\Http\ServerRequest$response ¶ protected
An instance of a Response object that contains information about the impending response
Type
Cake\Http\Response