Actions

Difference between revisions of "JModuleHelper/getModule"

From Joomla! Documentation

(Example)
Line 24: Line 24:
 
<source lang="php">
 
<source lang="php">
 
jimport('joomla.application.module.helper');
 
jimport('joomla.application.module.helper');
$module = JModuleHelper::getModule('login');
+
$module = JModuleHelper::getModule('mod_login');
 
echo '<pre>';
 
echo '<pre>';
 
print_r($module);
 
print_r($module);
Line 76: Line 76:
 
*/
 
*/
 
</source>
 
</source>
 +
 
===See also===
 
===See also===
 
* [[JModuleHelper/renderModule]]
 
* [[JModuleHelper/renderModule]]
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JModuleHelper]]</noinclude>
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JModuleHelper]]</noinclude>
 
'''Bold text'''
 
'''Bold text'''

Revision as of 15:43, 25 January 2009

Copyedit.png
This Article Needs Your Help

This article is tagged because it NEEDS REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.
More pages that need help similar to this one are here. NOTE-If you feel the need is satistified, please remove this notice.


Syntax

object getModule( $name[, $title= null])

where:

Argument Data type Description Default
$name string The name of the module
$title string The title of the module, optional null

Example

To get an installed Module, you can use the following example. This way the method checks if the module has been published, if the module is supposed to be displayed in this page, and if the user meets the access level expectations:

jimport('joomla.application.module.helper');
$module = JModuleHelper::getModule('mod_login');
echo '<pre>';
print_r($module);
echo '</pre>';
/* RESULT:
stdClass Object
(
    [id] => 18
    [title] => Login Form
    [module] => mod_login
    [position] => left
    [content] => 
    [showtitle] => 1
    [control] => 
    [params] => cache=0
                moduleclass_sfx=_login
                pretext=
                posttext=
                login=
                logout=
                greeting=1
                name=1
                usesecure=0
    [user] => 0
    [name] => login
    [style] => 
)
*/

You can also call for a custom module, that has not been installed via the Joomla Backend. $name has start with "mod_" in this case. The method then returns a standard object. It doesn't check if the module is published or not, it doesn't check if the user has the neccessary rights to see the module.

jimport('joomla.application.module.helper');
$module = JModuleHelper::getModule('mod_examplemodule');
echo '<pre>';
print_r($module);
echo '</pre>';
/*RESULT:
stdClass Object
(
    [id] => 0
    [title] => 
    [module] => mod_examplemodule
    [position] => 
    [content] => 
    [showtitle] => 0
    [control] => 
    [params] => 
    [user] => 0
)
*/

See also

Bold text