JMenu/getInstance: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Returns a JMenu object
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>
</spa... |
No edit summary |
||
| Line 1: | Line 1: | ||
===Description=== | ===Description=== | ||
Returns a JMenu object | Returns a reference to a JMenu object | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
| Line 9: | Line 9: | ||
===Syntax=== | ===Syntax=== | ||
<source lang="php"> | <source lang="php">& getInstance($client, $options=array())</source> | ||
{| class="wikitable" | {| class="wikitable" | ||
| Line 19: | Line 19: | ||
| $client | | $client | ||
| | | | ||
| The name of the client | | $client The name of the client | ||
|- | |- | ||
| $options | | $options | ||
| array() | | array() | ||
| An associative array of options | | $options An associative array of options | ||
|} | |} | ||
| 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(); | ||
} | } | ||
if (empty($instances[$client])) { | if (empty($instances[$client])) | ||
{ | |||
//Load the router object | //Load the router object | ||
$info = &JApplicationHelper::getClientInfo($client, true); | $info =& JApplicationHelper::getClientInfo($client, true); | ||
$path = $info->path.' | $path = $info->path.DS.'includes'.DS.'menu.php'; | ||
if (file_exists($path)) { | if(file_exists($path)) | ||
{ | |||
require_once $path; | require_once $path; | ||
| Line 55: | Line 57: | ||
$classname = 'JMenu'.ucfirst($client); | $classname = 'JMenu'.ucfirst($client); | ||
$instance = new $classname($options); | $instance = new $classname($options); | ||
} else { | } | ||
//$error = JError::raiseError(500, 'Unable to load menu: '.$client); | else | ||
{ | |||
//$error = JError::raiseError( 500, 'Unable to load menu: '.$client); | |||
$error = null; //Jinx : need to fix this | $error = null; //Jinx : need to fix this | ||
return $error; | return $error; | ||
Revision as of 22:10, 22 March 2010
Description
Returns a reference to a JMenu object
Template:Description:JMenu/getInstance
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];
}
[Edit See Also] Template:SeeAlso:JMenu/getInstance
Examples
<CodeExamplesForm />