Actions

JURI/setQuery

From Joomla! Documentation

Revision as of 17:20, 16 September 2008 by Chris Davenport (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 '&' 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