Source code for file /joomla/application/router.php
Documentation is available at router.php
* @version $Id:router.php 8876 2007-09-13 22:54:03Z jinx $
* @package Joomla.Framework
* @subpackage Application
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* Set the available masks for the routing mode
define('JROUTER_MODE_RAW', 0);
define('JROUTER_MODE_SEF', 1);
* Class to create and parse routes
* @package Joomla.Framework
* @subpackage Application
$this->_mode =
$options['mode'];
* Returns a reference to the global JRouter object, only creating it if it
* This method must be invoked as:
* <pre> $menu = &JRouter::getInstance();</pre>
* @param string $client The name of the client
* @param array $options An associative array of options
* @return JRouter A router object.
if (!isset
( $instances )) {
if (empty($instances[$client]))
$path =
$info->path.
DS.
'includes'.
DS.
'router.php';
// Create a JRouter object
$classname =
'JRouter'.
ucfirst($client);
$instance =
new $classname($options);
$instances[$client] =
& $instance;
return $instances[$client];
* Function to convert a route to an internal URI
// Process the parsed variables based on custom defined rules
* Function to convert an internal URI to a route
* @param string $string The internal URL
* @return string The absolute search engine friendly URL
//Process the uri information based on custom defined rules
// Build SEF URL : mysite/route/index.php?var=x
* Set a router variable, creating it if it doesn't exist
* @param string $key The name of the variable
* @param mixed $value The value of the variable
* @param boolean $create If True, the variable will be created if it doesn't exist yet
function setVar($key, $value, $create =
true) {
$this->_vars[$key] =
$value;
$this->_vars[$key] =
$value;
* Set the router variable array
* @param array $vars An associative array with variables
* @param boolean $create If True, the array will be merged instead of overwritten
function setVars($vars =
array(), $merge =
true) {
* @param string $key The name of the variable
* $return mixed Value of the variable
if(isset
($this->_vars[$key])) {
$result =
$this->_vars[$key];
* Get the router variable array
* @return array An associative array of router variables
* @param callback $callback The function to be called.
$this->_rules['build'][] =
$callback;
* @param callback $callback The function to be called.
$this->_rules['parse'][] =
$callback;
* Function to convert a raw route to an internal URI
* Function to convert a sef route to an internal URI
* Function to build a raw route
* Function to build a sef route
* Process the parsed router variables based on custom defined rules
foreach($this->_rules['parse'] as $rule) {
* Process the build uri query data based on custom defined rules
foreach($this->_rules['build'] as $rule) {
* Create a uri based on a full or partial url string
* @return JURI A JURI object
// Create full URL if we are only appending variables to it
if(strpos($url, '&') !==
false)
foreach($vars as $key =>
$var)
// Decompose link into url component parts
* @param array An array of route segments
$total =
count($segments);
for($i=
0; $i<
$total; $i++
) {
* @param array An array of route segments
$total =
count($segments);
for($i=
0; $i<
$total; $i++
) {