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.
__construct( Cake\Controller\ComponentRegistry $registry , array $config [] )
Constructor. Parses the accepted content types accepted by the client using HTTP_ACCEPT
Cake\Controller\ComponentRegistry
$registry
$config
optional [] Cake\Controller\Component::__construct()
_setExtension( Cake\Network\Request $request , Cake\Network\Response $response )
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\Network\Request
$request
Cake\Network\Response
$response
accepts( string|array $type null )
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\Network\Request::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.
$type
optional null mixed
addInputType( string $type , array $handler )
Add a new mapped input type. Mapped input types are automatically converted by RequestHandlerComponent during the startup() callback.
$type
$handler
Cake\Core\Exception\Exception
beforeRedirect( Cake\Event\Event $event , string|array $url , Cake\Network\Response $response )
Handles (fakes) redirects for AJAX requests using requestAction()
Cake\Event\Event
$event
$url
Cake\Network\Response
$response
Cake\Network\Response|null
beforeRender( Cake\Event\Event $event )
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.
controller/action.xml
is requested, the view path becomes app/View/Controller/xml/action.ctp
. Also if controller/action
is requested with Accept-Type: 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\Network\Response. If you need to declare additional mime-types, you can do so using Cake\Network\Response::type() in your controller's beforeFilter() method.Cake\Event\Event
$event
boolean
convertXml( string $xml )
Helper method to parse xml input data, due to lack of anonymous functions this lives here.
$xml
array
implementedEvents( )
Events supported by this component.
array
Cake\Controller\Component::implementedEvents()
initialize( array $config )
Checks to see if a specific content type has been requested and sets RequestHandler::$ext accordingly. Checks the following in order: 1. The '_ext' value parsed by the Router. 2. A specific AJAX type request indicated by the presence of a header. 3. The Accept header. With the exception of an AJAX request indicated using the second header based method above, the type must have been configured in Cake\Routing\Router
.
$config
Cake\Controller\Component::initialize()
isAtom( )
Returns true if the current call accepts an Atom response, false otherwise
boolean
isMobile( )
Returns true if user agent string matches a mobile web browser, or if the client accepts WAP content.
boolean
isRss( )
Returns true if the current call accepts an RSS response, false otherwise
boolean
isXml( )
Returns true if the current call accepts an XML response, false otherwise
boolean
mapAlias( string|array $alias )
Maps a content type alias back to its mime-type(s)
$alias
string|null|array
prefers( string|array $type null )
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.
$type
optional null mixed
renderAs( Cake\Controller\Controller $controller , string $type , array $options [] )
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
$type
$options
optional [] Cake\Controller\Component\RequestHandlerComponent::respondAs()
requestedWith( string|array $type null )
Determines the content type of the data the client has sent (i.e. in a POST request)
$type
optional null mixed
respondAs( string|array $type , array $options [] )
Sets the response header based on type map index name. This wraps several methods available on Cake\Network\Response. It also allows you to use Content-Type aliases.
$type
$options
optional [] boolean
responseType( )
Returns the current response type (Content-type header), or null if not alias exists
mixed
startup( Cake\Event\Event $event )
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
viewClassMap( array|string|null $type null , array|null $viewClass null )
Getter/setter for viewClassMap
$type
optional null ['type' => 'viewClass']
to map one or more$viewClass
optional null View
appendedarray|string
__debugInfo( )
Returns an array that can be used to describe the internal state of this object.
array
__get( string $name )
Magic method for lazy loading $components.
$name
mixed
_configDelete( string $key )
Delete a single config key
$key
Cake\Core\Exception\Exception
_configRead( string|null $key )
Read a config variable
$key
mixed
_configWrite( string|array $key , mixed $value , boolean|string $merge false )
Write a config variable
$key
$value
$merge
optional false Cake\Core\Exception\Exception
config( string|array|null $key null , mixed|null $value null , boolean $merge true )
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']);
$key
optional null $value
optional null $merge
optional true mixed
Cake\Core\Exception\Exception
configShallow( string|array $key , mixed|null $value null )
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->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']);
$key
$value
optional null mixed
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.
$msg
$level
optional LogLevel::ERROR $context
optional [] boolean
protected array
A component lookup table used to lazy load component objects.
[]
protected Cake\Controller\ComponentRegistry
Component registry class used to lazy load components.
protected boolean
Whether the config property has already been configured with defaults
false
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/3.1/class-Cake.Controller.Component.RequestHandlerComponent.html