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