$helpers
$helpers : array
An array containing the names of helpers this controller uses. The array elements should not contain the "Helper" part of the class name.
Example:
public $helpers = ['Form', 'Html', 'Time'];
Error Handling Controller
Controller used by ErrorHandler to render error views.
$request : \Cake\Http\ServerRequest
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.
Deprecated 3.6.0: The property will become protected in 4.0.0. Use getRequest()/setRequest instead.
None found |
$response : \Cake\Http\Response
An instance of a Response object that contains information about the impending response
Deprecated 3.6.0: The property will become protected in 4.0.0. Use getResponse()/setResponse instead.
None found |
$paginate : array
Settings for pagination.
Used to pre-configure pagination preferences for the various tables your controller will be paginating.
None found |
$components : array
Array containing the names of components this controller uses. Component names should not contain the "Component" portion of the class name.
Example:
public $components = ['RequestHandler', 'Acl'];
None found |
$View : \Cake\View\View
Instance of the View created during rendering. Won't be set until after Controller::render() is called.
None found |
None found |
$modelClass : string
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.
None found |
None found |
None found |
$Auth : \Cake\Controller\Component\AuthComponent
None found |
$Cookie : \Cake\Controller\Component\CookieComponent
None found |
$Csrf : \Cake\Controller\Component\CsrfComponent
None found |
$Flash : \Cake\Controller\Component\FlashComponent
None found |
$Paginator : \Cake\Controller\Component\PaginatorComponent
None found |
$RequestHandler : \Cake\Controller\Component\RequestHandlerComponent
None found |
$Security : \Cake\Controller\Component\SecurityComponent
None found |
$name : string
The name of this controller. Controller names are plural, named after the model they manipulate.
Set automatically using conventions in Controller::__construct().
None found |
$_responseClass : string
The class name to use for creating the response object.
None found |
$autoRender : boolean
Set to true to automatically render the view after action logic.
None found |
$_components : \Cake\Controller\ComponentRegistry
Instance of ComponentRegistry used to create Components
None found |
$_validViewOptions : array
These Controller properties will be passed from the Controller to the View as options.
None found |
None found |
$_eventManager : \Cake\Event\EventManagerInterface|\Cake\Event\EventManager
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
None found |
None found |
$_tableLocator : \Cake\ORM\Locator\LocatorInterface
Table locator instance
None found |
None found |
None found |
$_viewBuilder : \Cake\View\ViewBuilder
The view builder instance being used.
None found |
__construct(\Cake\Http\ServerRequest|null $request = null, \Cake\Http\Response|null $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.
\Cake\Http\ServerRequest|null | $request | 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 | Response object for this controller. |
string|null | $name | Override the name useful in testing when using mocks. |
\Cake\Event\EventManager|null | $eventManager | The event manager. Defaults to a new instance. |
\Cake\Controller\ComponentRegistry|null | $components | The component registry. Defaults to a new instance. |
None found |
initialize() : void
Initialization hook method.
Implement this method to avoid having to overwrite the constructor and call parent.
None found |
components(\Cake\Controller\ComponentRegistry|null $components = null) : \Cake\Controller\ComponentRegistry
Get the component registry for this controller.
If called with the first parameter, it will be set as the controller $this->_components property
\Cake\Controller\ComponentRegistry|null | $components | Component registry. |
None found |
loadComponent(string $name, array $config = array()) : \Cake\Controller\Component
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.
string | $name | The name of the component to load. |
array | $config | The config for the component. |
None found |
__get(string $name) : boolean|object
Magic accessor for model autoloading.
string | $name | Property name |
The model instance or false
None found |
__set(string $name, mixed $value) : void
Magic setter for removed properties.
string | $name | Property name. |
mixed | $value | Value to set. |
None found |
since | 3.6.0 |
---|
setName(string $name) : $this
Sets the controller name.
string | $name | Controller name. |
since | 3.6.0 |
---|
since | 3.6.0 |
---|
setPlugin(string $name) : $this
Sets the plugin name.
string | $name | Plugin name. |
since | 3.6.0 |
---|
isAutoRenderEnabled() : boolean
Returns true if an action should be rendered automatically.
since | 3.6.0 |
---|
since | 3.6.0 |
---|
since | 3.6.0 |
---|
getRequest() : \Cake\Http\ServerRequest
Gets the request instance.
since | 3.6.0 |
---|
setRequest(\Cake\Http\ServerRequest $request) : $this
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:
\Cake\Http\ServerRequest | $request | Request instance. |
None found |
getResponse() : \Cake\Http\Response
Gets the response instance.
since | 3.6.0 |
---|
setResponse(\Cake\Http\Response $response) : $this
Sets the response instance.
\Cake\Http\Response | $response | Response instance. |
since | 3.6.0 |
---|
invokeAction() : mixed
Dispatches the controller action. Checks that the action exists and isn't private.
The resulting response.
None found |
implementedEvents() : array
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
None found |
startupProcess() : \Cake\Http\Response|null
Perform the startup process for this controller.
Fire the Components and Controller callbacks in the correct order.
initialize
callbackbeforeFilter
.startup
methods.None found |
shutdownProcess() : \Cake\Http\Response|null
Perform the various shutdown processes for this controller.
Fire the Components and Controller callbacks in the correct order.
shutdown
callback.afterFilter
method.None found |
redirect(string|array $url, integer $status = 302) : \Cake\Http\Response|null
Redirects to given $url, after turning off $this->autoRender.
string|array | $url | A string or array-based URL pointing to another location within the app, or an absolute URL |
integer | $status | HTTP status code (eg: 301) |
None found |
setAction(string $action, array ...$args) : mixed
Internally redirects one action to another. Does not perform another HTTP request unlike Controller::redirect()
Examples:
setAction('another_action');
setAction('action_with_parameters', $parameter1);
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. |
array | $args variadic | Arguments passed to the action |
Returns the return value of the called action
None found |
render(string|null $view = null, string|null $layout = null) : \Cake\Http\Response
Instantiates the correct view class, hands it its data, and uses it to render the view output.
string|null | $view | View to use for rendering |
string|null | $layout | Layout to use |
A response object containing the rendered view.
None found |
referer(string|array|null $default = null, boolean $local = false) : string
Returns the referring URL for this request.
string|array|null | $default | Default URL to use if HTTP_REFERER cannot be read from headers |
boolean | $local | If true, restrict referring URLs to local server |
Referring URL
None found |
paginate(\Cake\ORM\Table|string|\Cake\ORM\Query|null $object = null, array $settings = array()) : \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface
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.
\Cake\ORM\Table|string|\Cake\ORM\Query|null | $object | Table to paginate (e.g: Table instance, 'TableName' or a Query object) |
array | $settings | The settings/configuration used for pagination. |
When no compatible table object can be found.
Query results
None found |
isAction(string $action) : boolean
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.
string | $action | The action to check. |
Whether or not the method is accessible from a URL.
None found |
beforeFilter(\Cake\Event\Event $event) : \Cake\Http\Response|null
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.
\Cake\Event\Event | $event | An Event instance |
None found |
beforeRender(\Cake\Event\Event $event) : void
beforeRender callback.
\Cake\Event\Event | $event | Event. |
None found |
beforeRedirect(\Cake\Event\Event $event, string|array $url, \Cake\Http\Response $response) : \Cake\Http\Response|null
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.
\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. |
None found |
afterFilter(\Cake\Event\Event $event) : \Cake\Http\Response|null
Called after the controller action is run and rendered.
\Cake\Event\Event | $event | An Event instance |
None found |
eventManager(\Cake\Event\EventManager|null $eventManager = null) : \Cake\Event\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.
\Cake\Event\EventManager|null | $eventManager | the eventManager to set |
None found |
getEventManager() : \Cake\Event\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.
None found |
setEventManager(\Cake\Event\EventManager $eventManager) : $this
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.
\Cake\Event\EventManager | $eventManager | the eventManager to set |
None found |
dispatchEvent(string $name, array|null $data = null, object|null $subject = null) : \Cake\Event\Event
Wrapper for creating and dispatching events.
Returns a dispatched event.
string | $name | Name of the event. |
array|null | $data | Any value you wish to be transported with this event to it can be read by listeners. |
object|null | $subject | The object that this event applies to ($this by default). |
None found |
tableLocator(\Cake\ORM\Locator\LocatorInterface|null $tableLocator = null) : \Cake\ORM\Locator\LocatorInterface
Sets the table locator.
If no parameters are passed, it will return the currently used locator.
\Cake\ORM\Locator\LocatorInterface|null | $tableLocator | LocatorInterface instance. |
None found |
setTableLocator(\Cake\ORM\Locator\LocatorInterface $tableLocator) : $this
Sets the table locator.
\Cake\ORM\Locator\LocatorInterface | $tableLocator | LocatorInterface instance. |
None found |
getTableLocator() : \Cake\ORM\Locator\LocatorInterface
Gets the table locator.
None found |
log(mixed $msg, integer|string $level = \Psr\Log\LogLevel::ERROR, string|array $context = array()) : boolean
Convenience method to write a message to Log. See Log::write() for more information on writing to logs.
mixed | $msg | Log message. |
integer|string | $level | Error level. |
string|array | $context | Additional log data relevant to this message. |
Success of log write.
None found |
loadModel(string|null $modelClass = null, string|null $modelType = null) : \Cake\Datasource\RepositoryInterface
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.
string|null | $modelClass | Name of model class to load. Defaults to $this->modelClass |
string|null | $modelType | The type of repository to load. Defaults to the modelType() value. |
If the model class cannot be found.
When using a type that has not been registered.
If no model type has been defined
The model instance created.
None found |
modelFactory(string $type, callable $factory) : void
Override a existing callable to generate repositories of a given type.
string | $type | The name of the repository type the factory function is for. |
callable | $factory | The factory function used to create instances. |
None found |
None found |
setModelType(string $modelType) : $this
Set the model type to be used by this class
string | $modelType | The model type |
None found |
modelType(string|null $modelType = null) : string|$this
Set or get the model type to be used by this class
string|null | $modelType | The model type or null to retrieve the current |
None found |
requestAction(string|array $url, array $extra = array()) : mixed
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()
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']);
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],
]);
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']
]);
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)
]);
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 | if array includes the key "return" it sets the autoRender to true. Can also be used to submit GET/POST data, and passed arguments. |
Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
None found |
viewBuilder() : \Cake\View\ViewBuilder
Get the view builder being used.
None found |
createView(string|null $viewClass = null) : \Cake\View\View
Constructs the view class instance based on the current configuration.
string|null | $viewClass | Optional namespaced class name of the View class to instantiate. |
If view class was not found.
None found |
set(string|array $name, mixed $value = null) : $this
Saves a variable or an associative array of variables for use inside a template.
string|array | $name | A string or an array of data. |
mixed | $value | 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. |
None found |
viewOptions(string|array|null $options = null, boolean $merge = true) : array
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()`.
string|array|null | $options | string or array of string to be appended to _validViewOptions. |
boolean | $merge | Whether to merge with or override existing valid View options.
Defaults to |
The updated view options as an array.
None found |
None found |
_mergeControllerVars() : void
Merge components, helpers vars from parent classes.
None found |
_loadComponents() : void
Loads the defined components using the Component factory.
None found |
_viewPath() : string
Get the viewPath based on controller name and request prefix.
None found |
_mergeVars(array $properties, array $options = array()) : void
Merge the list of $properties with all parent classes of the current class.
associative
- A list of properties that should be treated as associative arrays.
Properties in this list will be passed through Hash::normalize() before merging.array | $properties | An array of properties and the merge strategy for them. |
array | $options | The options to use when merging properties. |
None found |
_mergeProperty(string $property, array $parentClasses, array $options) : void
Merge a single property with the values declared in all parent classes.
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() |
None found |
_mergePropertyData(array $current, array $parent, boolean $isAssoc) : mixed
Merge each of the keys in a property together.
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. |
The updated value.
None found |
_setModelClass(string $name) : void
Set the modelClass and modelKey properties based on conventions.
If the properties are already set they will not be overwritten
string | $name | Class name. |
None found |