JModuleHelper/getModule: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Get module by name (real, eg 'Breadcrumbs' or folder, eg 'mod_breadcrumbs')
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JModule... |
m preparing for archive only |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 3: | Line 3: | ||
<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">& getModule($name, $title=null)</source> | ||
{| class="wikitable" | {| class="wikitable" | ||
| Line 23: | Line 23: | ||
| $title | | $title | ||
| null | | null | ||
| $title The title of the module, optional | | $title The title of the module, optional | ||
|} | |} | ||
| Line 36: | Line 36: | ||
===Source Body=== | ===Source Body=== | ||
<source lang="php"> | <source lang="php"> | ||
function &getModule($name, $title = null ) | |||
{ | { | ||
$result = null; | $result = null; | ||
$modules = &JModuleHelper::_load(); | $modules =& JModuleHelper::_load(); | ||
$total = count($modules); | $total = count($modules); | ||
for ($i = 0; $i < $total; $i++) | for ($i = 0; $i < $total; $i++) | ||
| Line 47: | Line 47: | ||
{ | { | ||
// Match the title if we're looking for a specific instance of the module | // Match the title if we're looking for a specific instance of the module | ||
if (!$title || $modules[$i]->title == $title) | if ( ! $title || $modules[$i]->title == $title ) | ||
{ | { | ||
$result = &$modules[$i]; | $result =& $modules[$i]; | ||
break; // Found it | break; // Found it | ||
} | } | ||
| Line 56: | Line 56: | ||
// if we didn't find it, and the name is mod_something, create a dummy object | // if we didn't find it, and the name is mod_something, create a dummy object | ||
if (is_null($result) && substr($name, 0, 4) == 'mod_') | if (is_null( $result ) && substr( $name, 0, 4 ) == 'mod_') | ||
{ | { | ||
$result = new stdClass; | $result = new stdClass; | ||
| Line 75: | Line 75: | ||
<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=getModule | category=getModule | ||
category=JModuleHelper | category=JModuleHelper | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
[[Category:Archived pages API15]] | |||
Latest revision as of 00:58, 25 March 2017
Description
Get module by name (real, eg 'Breadcrumbs' or folder, eg 'mod_breadcrumbs')
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
& getModule($name, $title=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| $name | $name The name of the module | |
| $title | null | $title The title of the module, optional |
Returns
object The Module object
Defined in
libraries/joomla/application/module/helper.php
Importing
jimport( 'joomla.application.module.helper' );
Source Body
function &getModule($name, $title = null )
{
$result = null;
$modules =& JModuleHelper::_load();
$total = count($modules);
for ($i = 0; $i < $total; $i++)
{
// Match the name of the module
if ($modules[$i]->name == $name)
{
// Match the title if we're looking for a specific instance of the module
if ( ! $title || $modules[$i]->title == $title )
{
$result =& $modules[$i];
break; // Found it
}
}
}
// if we didn't find it, and the name is mod_something, create a dummy object
if (is_null( $result ) && substr( $name, 0, 4 ) == 'mod_')
{
$result = new stdClass;
$result->id = 0;
$result->title = '';
$result->module = $name;
$result->position = '';
$result->content = '';
$result->showtitle = 0;
$result->control = '';
$result->params = '';
$result->user = 0;
}
return $result;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples