Section: Retrieving HTTP parameters
|« Developing a controller||^ Developing a module||Using the CRUD controller »|
Forget $_GET and $_POST variables ¶
In an action of a controller, one of task you'll do very often, is to retrieve HTTP parameters.
In PHP, you usually get them into
However, except for files uploading (
$_FILES), you'll never use them. You must call one of the methods of
Your module used to be reusable, so it doesn't know how to retrieve parameters. For instance, depending of how URLS are configured (router), perhaps one of parameters is inside the pathinfo or in $_GET. A form could be changed, so parameters are in $_GET instead of $_POST. More important, HTTP parameters could be changed by a plugin, without changing original PHP arrays.
With other protocols like SOAP or XML-RPC, parameters can be stored into the body of the request. The Request object of jelix extract them for you.
This is why you have one unified way to retrieve a parameter: the method
param() of a controller. This is the same method for GET, POST, PUT, DELETE, SOAP, XML-RPC, JSON etc...
Accessing client-request parameters ¶
HTTP client-request parameters are accessible through an instance of
jRequest, which is accessible from
jCoordinator. For example :
$id = $GLOBALS['gJCoord']->request->getParam('id');
jController provides the method
$id = $this->param('id');
Fetching an undefined parameter makes
param() to return null or it's second argument for example:
$title = $this->param('title','Hello World (default title)');
jController provides a few filtering methods like
boolParam() which use the same arguments:
- intParam() to fetch an integer,
- floatParam() to fetch a float value,
- boolParam() returns
falseexcept if the parameter's string value is
jFilter for any other type of filtering.