Cakephp Classroom image

pankaj
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17|Last
Lessons:-Controllers

More on controllers
Request and Response objects
New in CakePHP 2.0 are request and response objects. In previous versions these objects were represented
through arrays, and the related methods were spread across RequestHandlerComponent, Router,
Dispatcher and Controller. There was no authoritative object on what information the request
contained. For 2.0, CakeRequest and CakeResponse are used for this purpose.
CakeRequest
CakeRequest is the default request object used in CakePHP. It centralizes a number of features for interrogating
and interacting with request data. On each request one CakeRequest is created and then passed
by reference to the various layers of an application that use request data. By default CakeRequest is
assigned to $this->request, and is available in Controller, Views and Helpers. You can also access it
in Components by using the controller reference. Some of the duties CakeRequest performs include:
• Process the GET, POST, and FILES arrays into the data structures you are familiar with.
• Provide environment introspection pertaining to the request. Things like the headers sent, the client’s
IP address, and the subdomain/domain information about the application the server is running on.• Provide access to request parameters both as array indices and object properties.
Accessing request parameters
CakeRequest exposes several interfaces for accessing request parameters. The first is as object properties,
the second is array indexes, and the third is through $this->request->params:
$this->request->controller;
$this->request[’controller’];
$this->request->params[’controller’];
All of the above will both access the same value. Multiple ways of accessing the parameters was done to
ease migration for existing applications. All Route elements are accessed through this interface.
In addition to Route elements you also often need access to Passed arguments and Named parameters. These
are both available on the request object as well:
// Passed arguments
$this->request->pass;
$this->request[’pass’];
$this->request->params[’pass’];
// named parameters
$this->request->named;
$this->request[’named’];
$this->request->params[’named’];
Will all provide you access to the passed arguments and named parameters. There are several important/
useful parameters that CakePHP uses internally, these are also all found in the request parameters:
• plugin The plugin handling the request, will be null for no plugin.
• controller The controller handling the current request.
• action The action handling the current request.
• prefix The prefix for the current action. See Prefix Routing for more information.
• bare Present when the request came from requestAction() and included the bare option. Bare requests
do not have layouts rendered.
• requested Present and set to true when the action came from requestAction.

 
 
 

pankaj

Skills    Cakephp

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)