Actions

Difference between revisions of "JURI/setQuery"

From Joomla! Documentation

(New page: Sets the query part of the URI represented by the JURI object. ===Syntax=== void setQuery( $query ) where: {| class="wikitable" !Argument !Data type !Description !Default |- |$query |stri...)
 
m (See also: re-categorisation)
 
Line 49: Line 49:
 
* [[JURI/getQuery|JURI->getQuery]]
 
* [[JURI/getQuery|JURI->getQuery]]
 
* [[JURI/buildQuery|JURI->buildQuery]]
 
* [[JURI/buildQuery|JURI->buildQuery]]
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JURI]]</noinclude>
+
<noinclude>[[Category:JURI]]</noinclude>

Latest revision as of 12:42, 9 August 2012

Sets the query part of the URI represented by the JURI object.

Contents

Syntax

void setQuery( $query )

where:

Argument Data type Description Default
$query string or array Query to be added to the URI. This will replace all existing query items. If the string form is used then both '&' and '&amp;' are accepted as query item separators.

Example 1

In this example, a URI object is created and the query is then changed using a given string.

$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";
$u->setQuery( 'task=save&id=17' );
echo 'After : ' . $u->toString();

would output

Before: http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=view&id=32#anchorthat
After : http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=save&id=17#anchorthat

Example 2

In this example, a URI object is created and the query is then changed using an array of query items.

$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";
$query = array( 'task' => 'log',
                'id'   => 128,
                'act'  => 'redirect'
              );
$u->setQuery( $query );
echo 'After : ' . $u->toString();

would output

Before: http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=view&id=32#anchorthat
After : http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=log&id=128&act=redirect#anchorthat

See also