class JRequest

JRequest Class

This class serves to provide the Joomla Platform with a common interface to access request variables. This includes $POST, $GET, and naturally $_REQUEST. Variables can be passed through an input filter to avoid injection or returned raw.

Methods

static  string
getUri()

Gets the full request path.

static  string
getMethod()

Gets the request method.

static  mixed
getVar( string $name, mixed $default = null, string $hash = 'default', string $type = 'none', integer $mask)

Fetches and returns a given variable.

static  integer
getInt( string $name, integer $default, string $hash = 'default')

Fetches and returns a given filtered variable. The integer filter will allow only digits and the - sign to be returned. This is currently only a proxy function for getVar().

static  integer
getUInt( string $name, integer $default, string $hash = 'default')

Fetches and returns a given filtered variable. The unsigned integer filter will allow only digits to be returned. This is currently only a proxy function for getVar().

static  float
getFloat( string $name, float $default = 0.0, string $hash = 'default')

Fetches and returns a given filtered variable. The float filter only allows digits and periods. This is currently only a proxy function for getVar().

static  boolean
getBool( string $name, boolean $default = false, string $hash = 'default')

Fetches and returns a given filtered variable. The bool filter will only return true/false bool values. This is currently only a proxy function for getVar().

static  string
getWord( string $name, string $default = '', string $hash = 'default')

Fetches and returns a given filtered variable. The word filter only allows the characters [A-Za-z_]. This is currently only a proxy function for getVar().

static  string
getCmd( string $name, string $default = '', string $hash = 'default')

Cmd (Word and Integer) filter

static  string
getString( string $name, string $default = '', string $hash = 'default', integer $mask)

Fetches and returns a given filtered variable. The string filter deletes 'bad' HTML code, if not overridden by the mask.

static  string
setVar( string $name, string $value = null, string $hash = 'method', boolean $overwrite = true)

Set a variable in one of the request variables.

static  mixed
get( string $hash = 'default', integer $mask)

Fetches and returns a request array.

static  void
set( array $array, string $hash = 'default', boolean $overwrite = true)

Sets a request variable.

static  boolean
checkToken( string $method = 'post')

Checks for a form token in the request.

Details

static string getUri()

Gets the full request path.

Return Value

string

static string getMethod()

Gets the request method.

Return Value

string

static mixed getVar( string $name, mixed $default = null, string $hash = 'default', string $type = 'none', integer $mask)

Fetches and returns a given variable.

The default behaviour is fetching variables depending on the current request method: GET and HEAD will result in returning an entry from $GET, POST and PUT will result in returning an entry from $POST.

You can force the source by setting the $hash parameter:

post $POST get $GET files $FILES cookie $COOKIE env $ENV server $SERVER method via current $SERVER['REQUESTMETHOD'] default $_REQUEST

Parameters

string $name Variable name.
mixed $default Default value if the variable does not exist.
string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD).
string $type Return type for the variable, for valid values see {@link JFilterInput::clean()}.
integer $mask Filter mask for the variable.

Return Value

mixed Requested variable.

static integer getInt( string $name, integer $default, string $hash = 'default')

Fetches and returns a given filtered variable. The integer filter will allow only digits and the - sign to be returned. This is currently only a proxy function for getVar().

See getVar() for more in-depth documentation on the parameters.

Parameters

string $name Variable name.
integer $default Default value if the variable does not exist.
string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD).

Return Value

integer Requested variable.

static integer getUInt( string $name, integer $default, string $hash = 'default')

Fetches and returns a given filtered variable. The unsigned integer filter will allow only digits to be returned. This is currently only a proxy function for getVar().

See getVar() for more in-depth documentation on the parameters.

Parameters

string $name Variable name.
integer $default Default value if the variable does not exist.
string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD).

Return Value

integer Requested variable.

static float getFloat( string $name, float $default = 0.0, string $hash = 'default')

Fetches and returns a given filtered variable. The float filter only allows digits and periods. This is currently only a proxy function for getVar().

See getVar() for more in-depth documentation on the parameters.

Parameters

string $name Variable name.
float $default Default value if the variable does not exist.
string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD).

Return Value

float Requested variable.

static boolean getBool( string $name, boolean $default = false, string $hash = 'default')

Fetches and returns a given filtered variable. The bool filter will only return true/false bool values. This is currently only a proxy function for getVar().

See getVar() for more in-depth documentation on the parameters.

Parameters

string $name Variable name.
boolean $default Default value if the variable does not exist.
string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD).

Return Value

boolean Requested variable.

static string getWord( string $name, string $default = '', string $hash = 'default')

Fetches and returns a given filtered variable. The word filter only allows the characters [A-Za-z_]. This is currently only a proxy function for getVar().

See getVar() for more in-depth documentation on the parameters.

Parameters

string $name Variable name.
string $default Default value if the variable does not exist.
string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD).

Return Value

string Requested variable.

static string getCmd( string $name, string $default = '', string $hash = 'default')

Cmd (Word and Integer) filter

Fetches and returns a given filtered variable. The cmd filter only allows the characters [A-Za-z0-9.-_]. This is currently only a proxy function for getVar().

See getVar() for more in-depth documentation on the parameters.

Parameters

string $name Variable name
string $default Default value if the variable does not exist
string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)

Return Value

string Requested variable

static string getString( string $name, string $default = '', string $hash = 'default', integer $mask)

Fetches and returns a given filtered variable. The string filter deletes 'bad' HTML code, if not overridden by the mask.

This is currently only a proxy function for getVar().

See getVar() for more in-depth documentation on the parameters.

Parameters

string $name Variable name
string $default Default value if the variable does not exist
string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
integer $mask Filter mask for the variable

Return Value

string Requested variable

static string setVar( string $name, string $value = null, string $hash = 'method', boolean $overwrite = true)

Set a variable in one of the request variables.

Parameters

string $name Name
string $value Value
string $hash Hash
boolean $overwrite Boolean

Return Value

string Previous value

static mixed get( string $hash = 'default', integer $mask)

Fetches and returns a request array.

The default behaviour is fetching variables depending on the current request method: GET and HEAD will result in returning $GET, POST and PUT will result in returning $POST.

You can force the source by setting the $hash parameter:

post $POST get $GET files $FILES cookie $COOKIE env $ENV server $SERVER method via current $SERVER['REQUESTMETHOD'] default $_REQUEST

Parameters

string $hash to get (POST, GET, FILES, METHOD).
integer $mask Filter mask for the variable.

Return Value

mixed Request hash.

See also

JInput

static void set( array $array, string $hash = 'default', boolean $overwrite = true)

Sets a request variable.

Parameters

array $array An associative array of key-value pairs.
string $hash The request variable to set (POST, GET, FILES, METHOD).
boolean $overwrite If true and an existing key is found, the value is overwritten, otherwise it is ignored.

Return Value

void

static boolean checkToken( string $method = 'post')

Checks for a form token in the request.

Use in conjunction with JHtml::_('form.token').

Parameters

string $method The request method in which to look for the token key.

Return Value

boolean True if found and valid, false otherwise.