API16:JRequest/setVar
From Joomla! Documentation
Description
Set a variabe in on of the request variables.
Syntax
static setVar($name, $value=null, $hash= 'method', $overwrite=true)
| Parameter Name | Default Value | Description |
|---|---|---|
| $name | $name Name | |
| $value | null | $value Value |
| $hash | 'method' | $hash Hash |
| $overwrite | true | $overwrite Boolean |
Returns
string Previous value
Defined in
libraries/joomla/environment/request.php
Importing
jimport( 'joomla.environment.request' );
Source Body
public static function setVar($name, $value = null, $hash = 'method', $overwrite = true)
{
//If overwrite is true, makes sure the variable hasn't been set yet
if (!$overwrite && array_key_exists($name, $_REQUEST)) {
return $_REQUEST[$name];
}
// Clean global request var
$GLOBALS['_JREQUEST'][$name] = array();
// Get the request hash value
$hash = strtoupper($hash);
if ($hash === 'METHOD') {
$hash = strtoupper($_SERVER['REQUEST_METHOD']);
}
$previous = array_key_exists($name, $_REQUEST) ? $_REQUEST[$name] : null;
switch ($hash)
{
case 'GET' :
$_GET[$name] = $value;
$_REQUEST[$name] = $value;
break;
case 'POST' :
$_POST[$name] = $value;
$_REQUEST[$name] = $value;
break;
case 'COOKIE' :
$_COOKIE[$name] = $value;
$_REQUEST[$name] = $value;
break;
case 'FILES' :
$_FILES[$name] = $value;
break;
case 'ENV':
$_ENV['name'] = $value;
break;
case 'SERVER':
$_SERVER['name'] = $value;
break;
}
// Mark this variable as 'SET'
$GLOBALS['_JREQUEST'][$name]['SET.'.$hash] = true;
$GLOBALS['_JREQUEST'][$name]['SET.REQUEST'] = true;
return $previous;
}
Examples
Code Examples