Support Joomla!

references:joomla.framework:environment:jrequest-getvar

getVar

API Package Subpackage Class Method Reference Last reviewed Doc status
API Home Package Joomla.Framework Subpackage Environment Class JRequest Method getVar Reference getVar() Never Work in Progress

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
method via current $_SERVER[’REQUEST_METHOD’]
default via default order (GET, POST, FILE)

Syntax

mixed getVar ( $name, $default, $hash, $type, $mask )

$name string is a string containing the variable name to fetch.
$default string is a string containing the default value if the variable does not exist. This parameter is optional and if omitted defaults to null.
$hash string is a string containing the name of the location from which to fetch the variable from. Where the var should come from (POST, GET, FILES, METHOD). This parameter is optional and if omitted defaults to ‘default’.
$type string is a string containing the return type for the variable. See the JInputFilter::clean method for valid values. This parameter is optional and if omitted defaults to ‘none’.
$mask int is an integer containing the filter mask for the variable. See the cleanVar method for more information. This parameter is optional and if omitted defaults to 0 (most strict).

Examples

Example 1

Fetch the ‘id’ variable assigning the value 0 if it does not exist.

Example 1

$id = JRequest::getVar( 'id', 0 );

Example 2

Fetch the ‘name’ variable, assigning the value ‘none’ if it doesn’t exist. The variable will be retrieved from the $_POST variable and will be treated as a string. Unsafe HTML will be filtered out.

Example 2

$name = JRequest::getVar( 'name', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML );

Example 3

Options can be combined by logically ORing them as here where trimming is also suppressed.

Example 3

$name = JRequest::getVar( 'name', 'none', 'POST', 'STRING', JREQUEST_ALLOWHTML | JREQUEST_NOTRIM );
 
references/joomla.framework/environment/jrequest-getvar.txt (5147 views) · Last modified: 2008/03/17 15:54 by chrisdavenport