Actions

API15

JRequest/setVar

From Joomla! Documentation

< API15:JRequest
Revision as of 08:33, 23 June 2010 by Listurlaugson (Talk | contribs)

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Set a variabe in one of the request variables

[Edit Descripton]

Description:JRequest/setVar

Syntax

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

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;
}

[Edit See Also] SeeAlso:JRequest/setVar

Examples

<CodeExamplesForm />