CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 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

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • Component
  • ComponentRegistry
  • Controller
  • ErrorController

Class ErrorController

Error Handling Controller

Controller used by ErrorHandler to render error views.

Cake\Controller\Controller implements Cake\Event\EventListenerInterface, Cake\Event\EventDispatcherInterface uses Cake\Event\EventDispatcherTrait , Cake\ORM\Locator\LocatorAwareTrait , Cake\Log\LogTrait , Cake\Utility\MergeVariablesTrait , Cake\Datasource\ModelAwareTrait , Cake\Routing\RequestActionTrait , Cake\View\ViewVarsTrait
Extended by Cake\Controller\ErrorController
Namespace: Cake\Controller
Location: Controller/ErrorController.php

Inherited Magic Properties

  • Auth, Cookie, Csrf, Flash, Paginator, RequestHandler, Security _validViewOptions

Inherited Properties

  • View, _components, _responseClass, _validViewOptions, autoRender, components, helpers, name, paginate, passedArgs, plugin, request, response _eventClass, _eventManager _tableLocator _modelFactories, _modelType, modelClass _viewBuilder, viewClass, viewVars

Method Summary

  • beforeRender() public
    beforeRender callback.
  • initialize() public
    Initialization hook method.

Method Detail

beforeRender() public ¶

beforeRender( Cake\Event\Event $event )

beforeRender callback.

Parameters
Cake\Event\Event $event
Event.
Overrides
Cake\Controller\Controller::beforeRender()

initialize() public ¶

initialize( )

Initialization hook method.

Overrides
Cake\Controller\Controller::initialize()

Methods inherited from Cake\Controller\Controller

__construct() public ¶

__construct( Cake\Http\ServerRequest $request = null , Cake\Http\Response $response = null , string|null $name = null , Cake\Event\EventManager|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 $request optional null

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 $response optional null
Response object for this controller.
string|null $name optional null
Override the name useful in testing when using mocks.
Cake\Event\EventManager|null $eventManager optional null
The event manager. Defaults to a new instance.
Cake\Controller\ComponentRegistry|null $components optional null
The component registry. Defaults to a new instance.

__get() public ¶

__get( string $name )

Magic accessor for model autoloading.

Parameters
string $name
Property name
Returns
boolean|object
The model instance or false

__set() public ¶

__set( string $name , mixed $value )

Magic setter for removed properties.

Parameters
string $name
Property name.
mixed $value
Value to set.

_loadComponents() protected ¶

_loadComponents( )

Loads the defined components using the Component factory.

_mergeControllerVars() protected ¶

_mergeControllerVars( )

Merge components, helpers vars from parent classes.

_viewPath() protected ¶

_viewPath( )

Get the viewPath based on controller name and request prefix.

Returns
string

afterFilter() public ¶

afterFilter( Cake\Event\Event $event )

Called after the controller action is run and rendered.

Parameters
Cake\Event\Event $event
An Event instance
Returns
Cake\Http\Response|null
Link
https://book.cakephp.org/3.0/en/controllers.html#request-life-cycle-callbacks

beforeFilter() public ¶

beforeFilter( Cake\Event\Event $event )

Called 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\Event $event
An Event instance
Returns
Cake\Http\Response|null
Link
https://book.cakephp.org/3.0/en/controllers.html#request-life-cycle-callbacks

beforeRedirect() public ¶

beforeRedirect( Cake\Event\Event $event , string|array $url , Cake\Http\Response $response )

The 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\Event $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
Link
https://book.cakephp.org/3.0/en/controllers.html#request-life-cycle-callbacks

components() public ¶

components( Cake\Controller\ComponentRegistry|null $components = null )

Get 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 null
Component registry.
Returns
Cake\Controller\ComponentRegistry

disableAutoRender() public ¶

disableAutoRender( )

Disable automatic action rendering.

Returns

$this
Since
3.6.0

enableAutoRender() public ¶

enableAutoRender( )

Enable automatic action rendering.

Returns

$this
Since
3.6.0

getName() public ¶

getName( )

Returns the controller name.

Returns
string
Since
3.6.0

getPlugin() public ¶

getPlugin( )

Returns the plugin name.

Returns
string|null
Since
3.6.0

getRequest() public ¶

getRequest( )

Gets the request instance.

Returns
Cake\Http\ServerRequest
Since
3.6.0

getResponse() public ¶

getResponse( )

Gets the response instance.

Returns
Cake\Http\Response
Since
3.6.0

implementedEvents() public ¶

implementedEvents( )

Returns 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

Returns
array
Implementation of
Cake\Event\EventListenerInterface::implementedEvents()

invokeAction() public ¶

invokeAction( )

Dispatches the controller action. Checks that the action exists and isn't private.

Returns
mixed
The resulting response.
Throws
ReflectionException

isAction() public ¶

isAction( string $action )

Method 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
boolean
Whether or not the method is accessible from a URL.
Throws
ReflectionException

isAutoRenderEnabled() public ¶

isAutoRenderEnabled( )

Returns true if an action should be rendered automatically.

Returns
boolean
Since
3.6.0

loadComponent() public ¶

loadComponent( string $name , array $config = [] )

Add 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\Component
Throws
Exception

paginate() public ¶

paginate( Cake\ORM\Table|string|Cake\ORM\Query|null $object = null , array $settings = [] )

Handles 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 null

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\ResultSetInterface
Query results
Throws
RuntimeException
When no compatible table object can be found.
Link
https://book.cakephp.org/3.0/en/controllers.html#paginating-a-model

redirect() public ¶

redirect( string|array $url , integer $status = 302 )

Redirects to given $url, after turning off $this->autoRender.

Parameters
string|array $url

A string or array-based URL pointing to another location within the app, or an absolute URL

integer $status optional 302
HTTP status code (eg: 301)
Returns
Cake\Http\Response|null
Link
https://book.cakephp.org/3.0/en/controllers.html#Controller::redirect

referer() public ¶

referer( string|array|null $default = null , boolean $local = false )

Returns the referring URL for this request.

Parameters
string|array|null $default optional null
Default URL to use if HTTP_REFERER cannot be read from headers
boolean $local optional false
If true, restrict referring URLs to local server
Returns
string
Referring URL

render() public ¶

render( string|null $view = null , string|null $layout = null )

Instantiates the correct view class, hands it its data, and uses it to render the view output.

Parameters
string|null $view optional null
View to use for rendering
string|null $layout optional null
Layout to use
Returns
Cake\Http\Response
A response object containing the rendered view.
Link
https://book.cakephp.org/3.0/en/controllers.html#rendering-a-view

setAction() public ¶

setAction( string $action , ... $args )

Internally 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.

... $args
$args Arguments passed to the action
Returns
mixed
Returns the return value of the called action

setName() public ¶

setName( string $name )

Sets the controller name.

Parameters
string $name
Controller name.
Returns

$this
Since
3.6.0

setPlugin() public ¶

setPlugin( string $name )

Sets the plugin name.

Parameters
string $name
Plugin name.
Returns

$this
Since
3.6.0

setRequest() public ¶

setRequest( Cake\Http\ServerRequest $request )

Sets 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
  • $this->passedArgs - Same as $request->params['pass]
Parameters
Cake\Http\ServerRequest $request
Request instance.
Returns

$this

setResponse() public ¶

setResponse( Cake\Http\Response $response )

Sets the response instance.

Parameters
Cake\Http\Response $response
Response instance.
Returns

$this
Since
3.6.0

shutdownProcess() public ¶

shutdownProcess( )

Perform the various shutdown processes for this controller. Fire the Components and Controller callbacks in the correct order.

  • triggers the component shutdown callback.
  • calls the Controller's afterFilter method.
Returns
Cake\Http\Response|null

startupProcess() public ¶

startupProcess( )

Perform the startup process for this controller. Fire the Components and Controller callbacks in the correct order.

  • Initializes components, which fires their initialize callback
  • Calls the controller beforeFilter.
  • triggers Component startup methods.
Returns
Cake\Http\Response|null

Methods used from Cake\Event\EventDispatcherTrait

dispatchEvent() public ¶

dispatchEvent( string $name , array|null $data = null , object|null $subject = null )

Wrapper for creating and dispatching events.

Returns a dispatched event.

Parameters
string $name
Name of the event.
array|null $data optional null

Any value you wish to be transported with this event to it can be read by listeners.

object|null $subject optional null

The object that this event applies to ($this by default).

Returns
Cake\Event\Event

eventManager() public deprecated ¶

eventManager( Cake\Event\EventManager $eventManager = null )

Returns 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.

Deprecated
3.5.0 Use getEventManager()/setEventManager() instead.
Parameters
Cake\Event\EventManager $eventManager optional null
the eventManager to set
Returns
Cake\Event\EventManager

getEventManager() public ¶

getEventManager( )

Returns 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\EventManager

setEventManager() public ¶

setEventManager( Cake\Event\EventManager $eventManager )

Returns 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.

Parameters
Cake\Event\EventManager $eventManager
the eventManager to set
Returns

$this

Methods used from Cake\ORM\Locator\LocatorAwareTrait

getTableLocator() public ¶

getTableLocator( )

Gets the table locator.

Returns
Cake\ORM\Locator\LocatorInterface

setTableLocator() public ¶

setTableLocator( Cake\ORM\Locator\LocatorInterface $tableLocator )

Sets the table locator.

Parameters
Cake\ORM\Locator\LocatorInterface $tableLocator
LocatorInterface instance.
Returns

$this

tableLocator() public deprecated ¶

tableLocator( Cake\ORM\Locator\LocatorInterface $tableLocator = null )

Sets the table locator. If no parameters are passed, it will return the currently used locator.

Deprecated
3.5.0 Use getTableLocator()/setTableLocator() instead.
Parameters
Cake\ORM\Locator\LocatorInterface $tableLocator optional null
LocatorInterface instance.
Returns
Cake\ORM\Locator\LocatorInterface

Methods used from Cake\Log\LogTrait

log() public ¶

log( mixed $msg , integer|string $level = LogLevel::ERROR , string|array $context = [] )

Convenience method to write a message to Log. See Log::write() for more information on writing to logs.

Parameters
mixed $msg
Log message.
integer|string $level optional LogLevel::ERROR
Error level.
string|array $context optional []
Additional log data relevant to this message.
Returns
boolean
Success of log write.

Methods used from Cake\Utility\MergeVariablesTrait

_mergeProperty() protected ¶

_mergeProperty( string $property , array $parentClasses , array $options )

Merge a single property with the values declared in all parent classes.

Parameters
string $property
The name of the property being merged.
array $parentClasses
An array of classes you want to merge with.
array $options
Options for merging the property, see _mergeVars()

_mergePropertyData() protected ¶

_mergePropertyData( array $current , array $parent , boolean $isAssoc )

Merge each of the keys in a property together.

Parameters
array $current
The current merged value.
array $parent
The parent class' value.
boolean $isAssoc
Whether or not the merging should be done in associative mode.
Returns
mixed
The updated value.

_mergeVars() protected ¶

_mergeVars( string[] $properties , array $options = [] )

Merge the list of $properties with all parent classes of the current class.

Options:

  • associative - A list of properties that should be treated as associative arrays. Properties in this list will be passed through Hash::normalize() before merging.
Parameters
string[] $properties
An array of properties and the merge strategy for them.
array $options optional []
The options to use when merging properties.

Methods used from Cake\Datasource\ModelAwareTrait

_setModelClass() protected ¶

_setModelClass( string $name )

Set the modelClass and modelKey properties based on conventions.

If the properties are already set they will not be overwritten

Parameters
string $name
Class name.

getModelType() public ¶

getModelType( )

Get the model type to be used by this class

Returns
string

loadModel() public ¶

loadModel( string|null $modelClass = null , string|null $modelType = null )

Loads 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 null

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 null
The type of repository to load. Defaults to the modelType() value.
Returns
Cake\Datasource\RepositoryInterface
The model instance created.
Throws
Cake\Datasource\Exception\MissingModelException
If the model class cannot be found.
InvalidArgumentException
When using a type that has not been registered.
UnexpectedValueException
If no model type has been defined

modelFactory() public ¶

modelFactory( string $type , callable $factory )

Override 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.

modelType() public deprecated ¶

modelType( string|null $modelType = null )

Set or get the model type to be used by this class

Deprecated
3.5.0 Use getModelType()/setModelType() instead.
Parameters
string|null $modelType optional null
The model type or null to retrieve the current
Returns
string|Cake\Datasource\ModelAwareTrait
$this

setModelType() public ¶

setModelType( string $modelType )

Set the model type to be used by this class

Parameters
string $modelType
The model type
Returns

$this

Methods used from Cake\Routing\RequestActionTrait

requestAction() public deprecated ¶

requestAction( string|array $url , array $extra = [] )

Calls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.

Under the hood this method uses Router::reverse() to convert the $url parameter into a string URL. You should use URL formats that are compatible with Router::reverse()

Examples

A basic example getting the return value of the controller action:

$variables = $this->requestAction('/articles/popular');

A basic example of request action to fetch a rendered page without the layout.

$viewHtml = $this->requestAction('/articles/popular', ['return']);

You can also pass the URL as an array:

$vars = $this->requestAction(['controller' => 'articles', 'action' => 'popular']);

Passing other request data

You can pass POST, GET, COOKIE and other data into the request using the appropriate keys. Cookies can be passed using the cookies key. Get parameters can be set with query and post data can be sent using the post key.

$vars = $this->requestAction('/articles/popular', [
  'query' => ['page' => 1],
  'cookies' => ['remember_me' => 1],
]);

Sending environment or header values

By default actions dispatched with this method will use the global $_SERVER and $_ENV values. If you want to override those values for a request action, you can specify the values:

$vars = $this->requestAction('/articles/popular', [
  'environment' => ['CONTENT_TYPE' => 'application/json']
]);

Transmitting the session

By default actions dispatched with this method will use the standard session object. If you want a particular session instance to be used, you need to specify it.

$vars = $this->requestAction('/articles/popular', [
  'session' => new Session($someSessionConfig)
]);
Deprecated
3.3.0 You should refactor your code to use View Cells instead of this method.
Parameters
string|array $url

String or array-based url. Unlike other url arrays in CakePHP, this url will not automatically handle passed arguments in the $url parameter.

array $extra optional []

if array includes the key "return" it sets the autoRender to true. Can also be used to submit GET/POST data, and passed arguments.

Returns
mixed

Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.


Methods used from Cake\View\ViewVarsTrait

createView() public ¶

createView( string|null $viewClass = null )

Constructs the view class instance based on the current configuration.

Parameters
string|null $viewClass optional null
Optional namespaced class name of the View class to instantiate.
Returns
Cake\View\View
Throws
Cake\View\Exception\MissingViewException
If view class was not found.

set() public ¶

set( string|array $name , mixed $value = null )

Saves 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 null

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

$this

viewBuilder() public ¶

viewBuilder( )

Get the view builder being used.

Returns
Cake\View\ViewBuilder

viewOptions() public deprecated ¶

viewOptions( string|array|null $options = null , boolean $merge = true )

Get/Set valid view options in the object's _validViewOptions property. The property is created as an empty array if it is not set. If called without any parameters it will return the current list of valid view options. See createView().

Deprecated
3.7.0 Use ViewBuilder::setOptions() or any one of it's setter methods instead.
Parameters
string|array|null $options optional null
string or array of string to be appended to _validViewOptions.
boolean $merge optional true

Whether to merge with or override existing valid View options. Defaults to true.

Returns
array
The updated view options as an array.

Magic methods inherited from Cake\Controller\Controller

isAuthorized()

Magic methods inherited from Cake\Event\EventDispatcherInterface

getEventManager()
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs