$request
$request : \Cake\Http\ServerRequest
Request object
Request object for handling alternative HTTP requests
Alternative HTTP requests can come from wireless units like mobile phones, palmtop computers, and the like. These units have no use for AJAX requests, and this Component can tell how Cake should respond to the different needs of a handheld computer and a desktop machine.
$request : \Cake\Http\ServerRequest
Request object
$response : \Cake\Http\Response
Response object
None found |
None found |
None found |
$ext : string|null
Contains the file extension parsed out by the Router
Deprecated as of 3.7.0. This property will be made protected in 4.0.0.
None found |
$ajaxLayout : string
Set the layout to be used when rendering the AuthComponent's ajaxLogin element.
None found |
$_registry : \Cake\Controller\ComponentRegistry
Component registry class used to lazy load components.
None found |
$_defaultConfig : array
Default config
These are merged with user-provided config when the component is used.
checkHttpCache
- Whether to check for HTTP cache.viewClassMap
- Mapping between type and view classes. If undefined
json, xml, and ajax will be mapped. Defining any types will omit the defaults.inputTypeMap
- A mapping between types and deserializers for request bodies.
If undefined json & xml will be mapped. Defining any types will omit the defaults.enableBeforeRedirect
- Set to false to disable the beforeRedirect
callback. The
beforeRedirect
functionality has been deprecated.None found |
$_componentMap : array
A component lookup table used to lazy load component objects.
None found |
None found |
$_configInitialized : boolean
Whether the config property has already been configured with defaults
None found |
$_renderType : string|null
The template to use when rendering the given content type.
None found |
__construct(\Cake\Controller\ComponentRegistry $registry, array $config = array())
Constructor. Parses the accepted content types accepted by the client using HTTP_ACCEPT
\Cake\Controller\ComponentRegistry | $registry | ComponentRegistry object. |
array | $config | Array of config. |
None found |
getController() : \Cake\Controller\Controller
Get the controller this component is bound to.
The bound controller.
None found |
initialize(array $config) : void
Constructor hook method.
Implement this method to avoid having to overwrite the constructor and call parent.
array | $config | The config data. |
None found |
__get(string $name) : mixed
Magic method for lazy loading $components.
string | $name | Name of component to get. |
A Component object or null.
None found |
implementedEvents() : array
Events supported by this component.
Uses Conventions to map controller events to standard component callback method names. By defining one of the callback methods a component is assumed to be interested in the related event.
Override this method if you need to add non-conventional event listeners. Or if you want components to listen to non-standard events.
None found |
__debugInfo() : array
Returns an array that can be used to describe the internal state of this object.
None found |
setConfig(string|array $key, mixed|null $value = null, boolean $merge = true) : $this
Sets the config.
Setting a specific value:
$this->setConfig('key', $value);
Setting a nested value:
$this->setConfig('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->setConfig(['one' => 'value', 'another' => 'value']);
string|array | $key | The key to set, or a complete array of configs. |
mixed|null | $value | The value to set. |
boolean | $merge | Whether to recursively merge or overwrite existing config, defaults to true. |
When trying to set a key that is invalid.
None found |
getConfig(string|null $key = null, mixed $default = null) : mixed
Returns the config.
Reading the whole config:
$this->getConfig();
Reading a specific value:
$this->getConfig('key');
Reading a nested value:
$this->getConfig('some.nested.key');
Reading with default value:
$this->getConfig('some-key', 'default-value');
string|null | $key | The key to get or null for the whole config. |
mixed | $default | The return value when the key does not exist. |
Config value being read.
None found |
config(string|array|null $key = null, mixed|null $value = null, boolean $merge = true) : mixed
Gets/Sets the config.
Reading the whole config:
$this->config();
Reading a specific value:
$this->config('key');
Reading a nested value:
$this->config('some.nested.key');
Setting a specific value:
$this->config('key', $value);
Setting a nested value:
$this->config('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->config(['one' => 'value', 'another' => 'value']);
string|array|null | $key | The key to get/set, or a complete array of configs. |
mixed|null | $value | The value to set. |
boolean | $merge | Whether to recursively merge or overwrite existing config, defaults to true. |
When trying to set a key that is invalid.
Config value being read, or the object itself on write operations.
None found |
configShallow(string|array $key, mixed|null $value = null) : $this
Merge provided config with existing config. Unlike `config()` which does a recursive merge for nested keys, this method does a simple merge.
Setting a specific value:
$this->configShallow('key', $value);
Setting a nested value:
$this->configShallow('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->configShallow(['one' => 'value', 'another' => 'value']);
string|array | $key | The key to set, or a complete array of configs. |
mixed|null | $value | The value to set. |
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 |
startup(\Cake\Event\Event $event) : void
The startup method of the RequestHandler enables several automatic behaviors related to the detection of certain properties of the HTTP request, including:
If the XML data is POSTed, the data is parsed into an XML object, which is assigned to the $data property of the controller, which can then be saved to a model object.
\Cake\Event\Event | $event | The startup event that was fired. |
None found |
convertXml(string $xml) : array
Helper method to parse xml input data, due to lack of anonymous functions this lives here.
string | $xml | XML string. |
Xml array data
None found |
beforeRedirect(\Cake\Event\Event $event, string|array $url, \Cake\Http\Response $response) : \Cake\Http\Response|null
Handles (fakes) redirects for AJAX requests using requestAction()
\Cake\Event\Event | $event | The Controller.beforeRedirect event. |
string|array | $url | A string or array containing the redirect location |
\Cake\Http\Response | $response | The response object. |
The response object if the redirect is caught.
None found |
beforeRender(\Cake\Event\Event $event) : boolean
Checks if the response can be considered different according to the request headers, and the caching response headers. If it was not modified, then the render process is skipped. And the client will get a blank response with a "304 Not Modified" header.
Accept
header. For example,
if controller/action.xml
is requested, the view path becomes
app/View/Controller/xml/action.ctp
. Also if controller/action
is
requested with Accept: application/xml
in the headers the view
path will become app/View/Controller/xml/action.ctp
. Layout and template
types will only switch to mime-types recognized by Cake\Http\Response.
If you need to declare additional mime-types, you can do so using
Cake\Http\Response::type() in your controller's beforeFilter() method.\Cake\Event\Event | $event | The Controller.beforeRender event. |
If invoked extension is not configured.
false if the render process should be aborted
None found |
isXml() : boolean
Returns true if the current call accepts an XML response, false otherwise
True if client accepts an XML response
None found |
isRss() : boolean
Returns true if the current call accepts an RSS response, false otherwise
True if client accepts an RSS response
None found |
isAtom() : boolean
Returns true if the current call accepts an Atom response, false otherwise
True if client accepts an Atom response
None found |
isMobile() : boolean
Returns true if user agent string matches a mobile web browser, or if the client accepts WAP content.
True if user agent is a mobile web browser
None found |
None found |
accepts(string|array|null $type = null) : mixed
Determines which content types the client accepts. Acceptance is based on the file extension parsed by the Router (if present), and by the HTTP_ACCEPT header. Unlike Cake\Http\ServerRequest::accepts() this method deals entirely with mapped content types.
Usage:
$this->RequestHandler->accepts(['xml', 'html', 'json']);
Returns true if the client accepts any of the supplied types.
$this->RequestHandler->accepts('xml');
Returns true if the client accepts xml.
string|array|null | $type | Can be null (or no parameter), a string type name, or an array of types |
If null or no parameter is passed, returns an array of content types the client accepts. If a string is passed, returns true if the client accepts it. If an array is passed, returns true if the client accepts one or more elements in the array.
None found |
requestedWith(string|array|null $type = null) : mixed
Determines the content type of the data the client has sent (i.e. in a POST request)
string|array|null | $type | Can be null (or no parameter), a string type name, or an array of types |
If a single type is supplied a boolean will be returned. If no type is provided The mapped value of CONTENT_TYPE will be returned. If an array is supplied the first type in the request content type will be returned.
None found |
prefers(string|array|null $type = null) : mixed
Determines which content-types the client prefers. If no parameters are given, the single content-type that the client most likely prefers is returned. If $type is an array, the first item in the array that the client accepts is returned.
Preference is determined primarily by the file extension parsed by the Router if provided, and secondarily by the list of content-types provided in HTTP_ACCEPT.
string|array|null | $type | An optional array of 'friendly' content-type names, i.e. 'html', 'xml', 'js', etc. |
If $type is null or not provided, the first content-type in the list, based on preference, is returned. If a single type is provided a boolean will be returned if that type is preferred. If an array of types are provided then the first preferred type is returned. If no type is provided the first preferred type is returned.
None found |
renderAs(\Cake\Controller\Controller $controller, string $type, array $options = array()) : void
Sets either the view class if one exists or the layout and template path of the view.
The names of these are derived from the $type input parameter.
Render the response as an 'ajax' response.
$this->RequestHandler->renderAs($this, 'ajax');
Render the response as an xml file and force the result as a file download.
$this->RequestHandler->renderAs($this, 'xml', ['attachment' => 'myfile.xml'];
\Cake\Controller\Controller | $controller | A reference to a controller object |
string | $type | Type of response to send (e.g: 'ajax') |
array | $options | Array of options to use |
None found |
respondAs(string|array $type, array $options = array()) : boolean
Sets the response header based on type map index name. This wraps several methods available on Cake\Http\Response. It also allows you to use Content-Type aliases.
string|array | $type | Friendly type name, i.e. 'html' or 'xml', or a full content-type, like 'application/x-shockwave'. |
array | $options | If $type is a friendly type name that is associated with more than one type of content, $index is used to select which content-type to use. |
Returns false if the friendly type name given in $type does not exist in the type map, or if the Content-type header has already been set by this method.
None found |
responseType() : mixed
Returns the current response type (Content-type header), or null if not alias exists
A string content type alias, or raw content type if no alias map exists, otherwise null
None found |
mapAlias(string|array $alias) : string|null|array
Maps a content type alias back to its mime-type(s)
string|array | $alias | String alias to convert back into a content type. Or an array of aliases to map. |
Null on an undefined alias. String value of the mapped alias type. If an alias maps to more than one content type, the first one will be returned. If an array is provided for $alias, an array of mapped types will be returned.
None found |
addInputType(string $type, array $handler) : void
Add a new mapped input type. Mapped input types are automatically converted by RequestHandlerComponent during the startup() callback.
string | $type | The type alias being converted, ie. json |
array | $handler | The handler array for the type. The first index should be the handling callback, all other arguments should be additional parameters for the handler. |
None found |
viewClassMap(array|string|null $type = null, array|null $viewClass = null) : array|string
Getter/setter for viewClassMap
array|string|null | $type | The type string or array with format |
array|null | $viewClass | The viewClass to be used for the type without |
Returns viewClass when only string $type is set, else array with viewClassMap
None found |
_configRead(string|null $key) : mixed
Reads a config key.
string|null | $key | Key to read. |
None found |
_configWrite(string|array $key, mixed $value, boolean|string $merge = false) : void
Writes a config key.
string|array | $key | Key to write to. |
mixed | $value | Value to write. |
boolean|string | $merge | True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false. |
if attempting to clobber existing config
None found |
_configDelete(string $key) : void
Deletes a single config key.
string | $key | Key to delete. |
if attempting to clobber existing config
None found |
_setExtension(\Cake\Http\ServerRequest $request, \Cake\Http\Response $response) : void
Set the extension based on the accept headers.
Compares the accepted types and configured extensions. If there is one common type, that is assigned as the ext/content type for the response. The type with the highest weight will be set. If the highest weight has more than one type matching the extensions, the order in which extensions are specified determines which type will be set.
If html is one of the preferred types, no content type will be set, this is to avoid issues with browsers that prefer HTML and several other content types.
\Cake\Http\ServerRequest | $request | The request instance. |
\Cake\Http\Response | $response | The response instance. |
None found |