JModuleHelper/getModule
From Joomla! Documentation
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 |
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 |
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] =>
)
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] =>
)
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
)