API15

Difference between revisions of "JRequest/getVar"

From Joomla! Documentation

< API15:JRequest
(New page: ===Description=== Fetches and returns a given variable. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</n...)
 
m (removing red link to edit, no existant pages)
(One intermediate revision by one other user not shown)
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JRequest/getVar|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JRequest/getVar}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 31: Line 31:
 
| $type
 
| $type
 
| 'none'
 
| 'none'
|  $type Return type for the variable, for valid values see
+
|  $type Return type for the variable, for valid values see [[Retrieving data from GET and POST requests]]
 
|-
 
|-
 
| $mask
 
| $mask
Line 119: Line 119:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JRequest/getVar|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JRequest/getVar}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 134: Line 134:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API15]]

Revision as of 13:44, 12 May 2013

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Fetches and returns a given variable.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax[edit]

getVar($name, $default=null, $hash= 'default', $type= 'none', $mask=0)
Parameter Name Default Value Description
$name $name Variable name
$default null $default Default value if the variable does not exist
$hash 'default' $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
$type 'none' $type Return type for the variable, for valid values see Retrieving data from GET and POST requests
$mask 0 $mask Filter mask for the variable

Returns[edit]

mixed Requested variable

Defined in[edit]

libraries/joomla/environment/request.php

Importing[edit]

jimport( 'joomla.environment.request' );

Source Body[edit]

function getVar($name, $default = null, $hash = 'default', $type = 'none', $mask = 0)
{
        // Ensure hash and type are uppercase
        $hash = strtoupper( $hash );
        if ($hash === 'METHOD') {
                $hash = strtoupper( $_SERVER['REQUEST_METHOD'] );
        }
        $type   = strtoupper( $type );
        $sig    = $hash.$type.$mask;

        // Get the input hash
        switch ($hash)
        {
                case 'GET' :
                        $input = &$_GET;
                        break;
                case 'POST' :
                        $input = &$_POST;
                        break;
                case 'FILES' :
                        $input = &$_FILES;
                        break;
                case 'COOKIE' :
                        $input = &$_COOKIE;
                        break;
                case 'ENV'    :
                        $input = &$_ENV;
                        break;
                case 'SERVER'    :
                        $input = &$_SERVER;
                        break;
                default:
                        $input = &$_REQUEST;
                        $hash = 'REQUEST';
                        break;
        }

        if (isset($GLOBALS['_JREQUEST'][$name]['SET.'.$hash]) && ($GLOBALS['_JREQUEST'][$name]['SET.'.$hash] === true)) {
                // Get the variable from the input hash
                $var = (isset($input[$name]) && $input[$name] !== null) ? $input[$name] : $default;
                $var = JRequest::_cleanVar($var, $mask, $type);
        }
        elseif (!isset($GLOBALS['_JREQUEST'][$name][$sig]))
        {
                if (isset($input[$name]) && $input[$name] !== null) {
                        // Get the variable from the input hash and clean it
                        $var = JRequest::_cleanVar($input[$name], $mask, $type);

                        // Handle magic quotes compatability
                        if (get_magic_quotes_gpc() && ($var != $default) && ($hash != 'FILES')) {
                                $var = JRequest::_stripSlashesRecursive( $var );
                        }

                        $GLOBALS['_JREQUEST'][$name][$sig] = $var;
                }
                elseif ($default !== null) {
                        // Clean the default value
                        $var = JRequest::_cleanVar($default, $mask, $type);
                }
                else {
                        $var = $default;
                }
        } else {
                $var = $GLOBALS['_JREQUEST'][$name][$sig];
        }

        return $var;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

<CodeExamplesForm />