JRouter/getInstance: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Returns the global JRouter object, only creating it if it doesn't already exist.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JR... |
m preparing for archive only |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
===Description=== | ===Description=== | ||
Returns the global JRouter object, only creating it if it doesn't already exist. | Returns a reference to the global JRouter object, only creating it if it doesn't already exist. | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
<nowiki>[< | <nowiki>[<! removed edit link to red link >]</nowiki> | ||
</span> | </span> | ||
<! removed transcluded page call, red link never existed > | |||
===Syntax=== | ===Syntax=== | ||
<source lang="php"> | <source lang="php">& getInstance($client, $options=array())</source> | ||
{| class="wikitable" | {| class="wikitable" | ||
| Line 36: | Line 36: | ||
===Source Body=== | ===Source Body=== | ||
<source lang="php"> | <source lang="php"> | ||
function &getInstance($client, $options = array()) | |||
{ | { | ||
static $instances; | static $instances; | ||
if (!isset($instances)) { | if (!isset( $instances )) { | ||
$instances = array(); | $instances = array(); | ||
} | } | ||
| Line 47: | Line 47: | ||
{ | { | ||
//Load the router object | //Load the router object | ||
$info = &JApplicationHelper::getClientInfo($client, true); | $info =& JApplicationHelper::getClientInfo($client, true); | ||
$path = $info->path.DS.'includes'.DS.'router.php'; | $path = $info->path.DS.'includes'.DS.'router.php'; | ||
if (file_exists($path)) | if(file_exists($path)) | ||
{ | { | ||
require_once $path; | require_once $path; | ||
| Line 60: | Line 60: | ||
else | else | ||
{ | { | ||
$error = JError::raiseError(500, 'Unable to load router: '.$client); | $error = JError::raiseError( 500, 'Unable to load router: '.$client); | ||
return $error; | return $error; | ||
} | } | ||
| Line 72: | Line 72: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
<nowiki>[< | <nowiki>[<! removed edit link to red link >]</nowiki> | ||
</span> | </span> | ||
<! removed transcluded page call, red link never existed > | |||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=getInstance | category=getInstance | ||
category=JRouter | category=JRouter | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
[[Category:Archived pages API15]] | |||
Latest revision as of 01:05, 25 March 2017
Description
Returns a reference to the global JRouter object, only creating it if it doesn't already exist.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
& getInstance($client, $options=array())
| Parameter Name | Default Value | Description |
|---|---|---|
| $client | $client The name of the client | |
| $options | array() | $options An associative array of options |
Returns
A router object.
Defined in
libraries/joomla/application/router.php
Importing
jimport( 'joomla.application.router' );
Source Body
function &getInstance($client, $options = array())
{
static $instances;
if (!isset( $instances )) {
$instances = array();
}
if (empty($instances[$client]))
{
//Load the router object
$info =& JApplicationHelper::getClientInfo($client, true);
$path = $info->path.DS.'includes'.DS.'router.php';
if(file_exists($path))
{
require_once $path;
// Create a JRouter object
$classname = 'JRouter'.ucfirst($client);
$instance = new $classname($options);
}
else
{
$error = JError::raiseError( 500, 'Unable to load router: '.$client);
return $error;
}
$instances[$client] = & $instance;
}
return $instances[$client];
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples