Actions

Difference between revisions of "JURI/setVar"

From Joomla! Documentation

(New page: 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, $v...)
 
m (See also: re-categorisation)
 
(One intermediate revision by one user not shown)
Line 22: Line 22:
  
 
===Example===
 
===Example===
In this example, a URI object is created and the user name is then changed.
+
In this example, a URI object is created and the task is then changed.
 
<source lang="php">
 
<source lang="php">
 
$uri = 'http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=view&id=32#anchorthis';
 
$uri = 'http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=view&id=32#anchorthis';
Line 34: Line 34:
 
  - old value of task was view
 
  - old value of task was view
 
  After : http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=save&id=32#anchorthis
 
  After : http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=save&id=32#anchorthis
 +
 
===See also===
 
===See also===
 
* [http://api.joomla.org/Joomla-Framework/Environment/JURI.html#setVar JURI->setVar on api.joomla.org]
 
* [http://api.joomla.org/Joomla-Framework/Environment/JURI.html#setVar JURI->setVar on api.joomla.org]
 
* [[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