JMenu/getInstance: Difference between revisions
From Joomla! Documentation
m removing red link to edit, no existant pages |
m preparing for archive only |
||
| Line 78: | Line 78: | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=getInstance | category=getInstance | ||
category=JMenu | category=JMenu | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
Latest revision as of 00:57, 25 March 2017
Description
Returns a reference to a JMenu object
[<! 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 menu object.
Defined in
libraries/joomla/application/menu.php
Importing
jimport( 'joomla.application.menu' );
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.'menu.php';
if(file_exists($path))
{
require_once $path;
// Create a JPathway object
$classname = 'JMenu'.ucfirst($client);
$instance = new $classname($options);
}
else
{
//$error = JError::raiseError( 500, 'Unable to load menu: '.$client);
$error = null; //Jinx : need to fix this
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