Class Controller

Controllers should provide a number of 'action' methods. These are public methods on the controller
that are not prefixed with a '_' and not part of Controller. Each action serves as an endpoint for
performing a specific action on a resource or collection of resources. For example: adding or editing a new
object, or listing a set of objects.

You can access request parameters, using $this->request. The request object contains all the POST, GET and FILES
that were part of the request.

After performing the required actions, controllers are responsible for creating a response. This usually
takes the form of a generated View, or possibly a redirection to another controller action. In either case
$this->response allows you to manipulate all aspects of the response.

Controllers are created by Dispatcher based on request parameters and routing. By default controllers and actions
use conventional names. For example /posts/index maps to PostsController::index(). You can re-map URLs
using Router::connect().

Used to define methods a controller that will be cached. To cache a
single action, the value is set to an array containing keys that match
action names and values that denote cache expiration times (in seconds).

An instance of a CakeRequest 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.

Shows a message to the user for $pause seconds, then redirects to $url.
Uses flash.ctp as the default layout for the message.
Does not work if the current debug level is higher than 0.

Returns the CakeEventManager manager instance that is handling any callbacks.
You can use this instance to register any new listeners or callbacks to the
controller events, or create your own events and trigger them at will.

Link

The beforeRedirect method is invoked when the controller's redirect method is called but before any
further action.

If this method returns false the controller will not continue on to redirect the request.
The $url, $status and $exit variables have same meaning as for the controller's method. You can also
return a string which will be interpreted as the URL to redirect to or return associative array with
key 'url' and optionally 'status' and 'exit'.

Parameters

string|array
$url

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

integer
$statusoptionalnull

Optional HTTP status code (eg: 404)

boolean
$exitoptionaltrue

If true, exit() will be called after the redirect

Returns

mixed

false to stop redirection event,
string controllers a new redirection URL or
array with the keys url, status and exit to be used by the redirect method.

Link

Returns the CakeEventManager manager instance that is handling any callbacks.
You can use this instance to register any new listeners or callbacks to the
controller events, or create your own events and trigger them at will.

Parameters

Deprecated

Since 2.4. Will be removed in 3.0. Use CakeResponse::httpCodes().

Parameters

integer|array
$codeoptionalnull

If $code is an integer, then the corresponding code/message is
returned if it exists, null if it does not exist. If $code is an array,
then the 'code' and 'message' keys of each nested array are added to the default
HTTP codes. Example:

Returns

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()

Passing POST and GET data

POST and GET data can be simulated in requestAction. Use $extra['url'] for
GET data. The $extra['data'] parameter allows POST data simulation.

Parameters

string|array
$url

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

array
$extraoptionalarray()

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

Returns

mixed

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

Used to define methods a controller that will be cached. To cache a
single action, the value is set to an array containing keys that match
action names and values that denote cache expiration times (in seconds).

An instance of a CakeRequest 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.