How to create a module for Joomla 2.5

User Rating:  / 18

We can create our own module for Joomla 2.5 CMS by writing our own code we follow the following procedure:

1. Decide a name. All modules start with mod_

   ( e.g : mod_mymodule )

2. create a directory (eg mod_mymodule) the following files:







file index.html :

View source
<html><body bgcolor="#FFFFFF"> </body></html>

file mod_mymodule.xml

View source
<?xml version="1.0" encoding="UTF-8"?>
    <name>My first module</name>
    <creationDate>07 February 2013</creationDate>
    <description>My first module in joomla 2.5</description>
        <filename module="mod_mymodule">mod_mymodule.php</filename>
        <fields name="params">
            <fieldset name="basic">
                    label="Parameter 1"
                    description="This is a Parameter 1 description">
                    label="Parameter 2"
                    description="This is a Parameter 2 description">
                    description="JFIELD_ALT_MODULE_LAYOUT_DESC" />
                    description="COM_MODULES_FIELD_MODULECLASS_SFX_DESC" />

file helper.php

View source
// My first module in joomla 2.5
class modMyModuleHelper {
    public function getMessage(&$params) {
        $par1 = $params->get('param1');
        $par2 = $params->get('param2');
        if ($par1 != NULL)
            $mess = 'Parameter 1 value : ' . $par1;
        if ($par2 != NULL)
            $mess = $mess . ' Parameter 2 value : ' . $par2;
        return $mess;

file mod_mymodule.php

View source
// My first modyle in Joomla 2.5
//no direct access
defined('_JEXEC') or die('Restricted access');
//include the syndicate functions only once
// Load helper class and functions
$message = modMyModuleHelper::getMessage($params);
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
// Load layout filefrom template views

file tmpl\index.html

View source
<html><body bgcolor="#FFFFFF"></body></html>

file tmpl\default.php

View source
// My first module in joomla 2.5 
// no direct access
defined('_JEXEC') or die('Restricted access !');
echo $message;

we make the which contains all the files you have created and do the installation on joomla:

Then go to the module list and we can parameterize.

We define two parameters for our example:

Put values in parameters activate the module and put it in the position that we want on our site.

The result is:

In this way we can create our own modules, to draw data from the database and present them the way we want our site.

The mod_mymodule we build for our example can be downloaded from here.

You have no rights to post comments





© Developerpages