JModuleHelper/getModule
From Joomla! Documentation
< JModuleHelper(Difference between revisions)
(→Example) |
m (Methods may be called statically.) |
||
| (One intermediate revision by one user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | Returns a stdClass object containing information about the module requested. A given module will only be returned if it meets the following criteria: | |
| + | * it is enabled; | ||
| + | * it is assigned to the current menu item or is assigned to all menu items; | ||
| + | * the user meets the access level requirements. | ||
| + | |||
===Syntax=== | ===Syntax=== | ||
| − | ''object'' getModule( $name | + | ''object'' getModule( $name, $title ) |
where: | where: | ||
| Line 12: | Line 16: | ||
|$name | |$name | ||
|string | |string | ||
| − | |The name of the module | + | |The name/type of the module. For example, 'login' for the login form module. If more than one module of this name/type exists and no title has been specified then the first module of the given name/type is returned. If the module is not found and the 'mod_' prefix has been used then a dummy stdClass object will be returned. |
| | | | ||
|- | |- | ||
|$title | |$title | ||
|string | |string | ||
| − | |The title of the module | + | |The title of the module. If '''null''' the first module of the given name/type is returned. |
|null | |null | ||
|} | |} | ||
| − | ===Example=== | + | ===Example 1=== |
| − | + | Obtain the login form module. | |
<source lang="php"> | <source lang="php"> | ||
| − | jimport('joomla.application.module.helper'); | + | jimport( 'joomla.application.module.helper' ); |
| − | $module = JModuleHelper::getModule(' | + | $module = JModuleHelper::getModule( 'login' ); |
echo '<pre>'; | echo '<pre>'; | ||
| − | print_r($module); | + | print_r( $module ); |
echo '</pre>'; | echo '</pre>'; | ||
| − | / | + | </source> |
| + | which will output: | ||
| + | <pre> | ||
stdClass Object | stdClass Object | ||
( | ( | ||
| Line 38: | Line 44: | ||
[showtitle] => 1 | [showtitle] => 1 | ||
[control] => | [control] => | ||
| − | [params] => | + | [params] => greeting=1 |
| − | + | name=0 | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | name | + | |
| − | + | ||
[user] => 0 | [user] => 0 | ||
[name] => login | [name] => login | ||
[style] => | [style] => | ||
| − | ) | + | )</pre> |
| − | + | ===Example 2=== | |
| − | </ | + | If more than one instance of a module exists then you can select the correct one by specifying its title. For example, there are usually many modules of type 'mod_mainmenu', so here we select the one with title "Resources": |
| − | + | <source lang="php"> | |
| + | jimport( 'joomla.application.module.helper' ); | ||
| + | $module = JModuleHelper::getModule( 'mainmenu', 'Resources' ); | ||
| + | echo '<pre>'; | ||
| + | print_r( $module ); | ||
| + | echo '</pre>';</source> | ||
| + | which will output: | ||
| + | <pre>stdClass Object | ||
| + | ( | ||
| + | [id] => 31 | ||
| + | [title] => Resources | ||
| + | [module] => mod_mainmenu | ||
| + | [position] => left | ||
| + | [content] => | ||
| + | [showtitle] => 0 | ||
| + | [control] => | ||
| + | [params] => menutype=othermenu | ||
| + | menu_style=list | ||
| + | startLevel=0 | ||
| + | endLevel=0 | ||
| + | showAllChildren=0 | ||
| + | window_open= | ||
| + | show_whitespace=0 | ||
| + | cache=1 | ||
| + | tag_id= | ||
| + | class_sfx= | ||
| + | moduleclass_sfx=_menu | ||
| + | maxdepth=10 | ||
| + | menu_images=0 | ||
| + | menu_images_align=0 | ||
| + | menu_images_link=0 | ||
| + | expand_menu=0 | ||
| + | activate_parent=0 | ||
| + | full_active_id=0 | ||
| + | indent_image=0 | ||
| + | indent_image1= | ||
| + | indent_image2= | ||
| + | indent_image3= | ||
| + | indent_image4= | ||
| + | indent_image5= | ||
| + | indent_image6= | ||
| + | spacer= | ||
| + | end_spacer= | ||
| + | |||
| + | [user] => 0 | ||
| + | [name] => mainmenu | ||
| + | [style] => | ||
| + | ) | ||
| + | </pre> | ||
| + | ===Example 3=== | ||
| + | If the module does not exist and it has the prefix 'mod_' then a dummy stdClass module object will be returned. | ||
<source lang="php"> | <source lang="php"> | ||
| − | jimport('joomla.application.module.helper'); | + | jimport( 'joomla.application.module.helper' ); |
| − | $module = JModuleHelper::getModule('mod_examplemodule'); | + | $module = JModuleHelper::getModule( 'mod_examplemodule' ); |
echo '<pre>'; | echo '<pre>'; | ||
| − | print_r($module); | + | print_r( $module ); |
echo '</pre>'; | echo '</pre>'; | ||
| − | / | + | </source> |
| − | stdClass Object | + | which will output: |
| + | <pre>stdClass Object | ||
( | ( | ||
[id] => 0 | [id] => 0 | ||
| Line 74: | Line 124: | ||
[user] => 0 | [user] => 0 | ||
) | ) | ||
| − | + | </pre> | |
| − | </ | + | |
===See also=== | ===See also=== | ||
| − | * [[JModuleHelper/renderModule]] | + | * [http://api.joomla.org/Joomla-Framework/Application/JModuleHelper.html#getModule JModuleHelper::getModule on api.joomla.org] |
| + | * [[JModuleHelper/getModules|JModuleHelper::getModules]] | ||
| + | * [[JModuleHelper/renderModule|JModuleHelper::renderModule]] | ||
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JModuleHelper]]</noinclude> | <noinclude>[[Category:Development]][[Category:Framework]][[Category:JModuleHelper]]</noinclude> | ||
| − | |||
Latest revision as of 14:54, 7 February 2009
Returns a stdClass object containing information about the module requested. A given module will only be returned if it meets the following criteria:
- it is enabled;
- it is assigned to the current menu item or is assigned to all menu items;
- the user meets the access level requirements.
Contents |
[edit] Syntax
object getModule( $name, $title )
where:
| Argument | Data type | Description | Default |
|---|---|---|---|
| $name | string | The name/type of the module. For example, 'login' for the login form module. If more than one module of this name/type exists and no title has been specified then the first module of the given name/type is returned. If the module is not found and the 'mod_' prefix has been used then a dummy stdClass object will be returned. | |
| $title | string | The title of the module. If null the first module of the given name/type is returned. | null |
[edit] Example 1
Obtain the login form module.
jimport( 'joomla.application.module.helper' ); $module = JModuleHelper::getModule( 'login' ); echo '<pre>'; print_r( $module ); echo '</pre>';
which will output:
stdClass Object
(
[id] => 18
[title] => Login Form
[module] => mod_login
[position] => left
[content] =>
[showtitle] => 1
[control] =>
[params] => greeting=1
name=0
[user] => 0
[name] => login
[style] =>
)
[edit] Example 2
If more than one instance of a module exists then you can select the correct one by specifying its title. For example, there are usually many modules of type 'mod_mainmenu', so here we select the one with title "Resources":
jimport( 'joomla.application.module.helper' ); $module = JModuleHelper::getModule( 'mainmenu', 'Resources' ); echo '<pre>'; print_r( $module ); echo '</pre>';
which will output:
stdClass Object
(
[id] => 31
[title] => Resources
[module] => mod_mainmenu
[position] => left
[content] =>
[showtitle] => 0
[control] =>
[params] => menutype=othermenu
menu_style=list
startLevel=0
endLevel=0
showAllChildren=0
window_open=
show_whitespace=0
cache=1
tag_id=
class_sfx=
moduleclass_sfx=_menu
maxdepth=10
menu_images=0
menu_images_align=0
menu_images_link=0
expand_menu=0
activate_parent=0
full_active_id=0
indent_image=0
indent_image1=
indent_image2=
indent_image3=
indent_image4=
indent_image5=
indent_image6=
spacer=
end_spacer=
[user] => 0
[name] => mainmenu
[style] =>
)
[edit] Example 3
If the module does not exist and it has the prefix 'mod_' then a dummy stdClass module object will be returned.
jimport( 'joomla.application.module.helper' ); $module = JModuleHelper::getModule( 'mod_examplemodule' ); echo '<pre>'; print_r( $module ); echo '</pre>';
which will output:
stdClass Object
(
[id] => 0
[title] =>
[module] => mod_examplemodule
[position] =>
[content] =>
[showtitle] => 0
[control] =>
[params] =>
[user] => 0
)