Actions

Difference between revisions of "JURI/setVar"

From Joomla! Documentation

m (Example: small error in desc)
m (See also: re-categorisation)
 
Line 39: Line 39:
 
* [[JURI/getVar|JURI->getVar]]
 
* [[JURI/getVar|JURI->getVar]]
 
* [[JURI/delVar|JURI->delVar]]
 
* [[JURI/delVar|JURI->delVar]]
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JURI]]</noinclude>
+
<noinclude>[[Category:JURI]]</noinclude>

Latest revision as of 12:43, 9 August 2012

Sets an individual query item in the query part of the URI represented by the URI object. Returns the previous value of the query item if it existed.

Syntax

string setVar( $name, $value )

where:

Argument Data type Description Default
$name string Name of the query item to be set.
$value string Value of the query item to be set.

Example

In this example, a URI object is created and the task is then changed.

$uri = 'http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=view&id=32#anchorthis';
$u =& JURI::getInstance( $uri );
echo 'Before: ' . $u->toString() . "\n";
echo '- old value of task was ' . $u->setVar( 'task', 'save' ) . "\n";
echo 'After : ' . $u->toString();

would output

Before: http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=view&id=32#anchorthis
- old value of task was view
After : http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=save&id=32#anchorthis

See also