How to create a module for Joomla 2.5



User Rating:  / 18
PoorBest 
Details

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:

    index.html

    helper.php

    mod_mymodule.xml

    mod_mymodule.php

   \tmpl\default.php

   \tmpl\index.html

file index.html :

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

file mod_mymodule.xml

View source
<?xml version="1.0" encoding="UTF-8"?>
 
<extension
    type="module"
    version="2.5"
    client="site"
    method="upgrade">
    <name>My first module</name>
    <creationDate>07 February 2013</creationDate>
    <author>www.developerpages.gr</author>
    <version>1.0</version>
    <description>My first module in joomla 2.5</description>
    <files>
        <filename module="mod_mymodule">mod_mymodule.php</filename>
        <filename>index.html</filename>
        <filename>helper.php</filename>
        <filename>mod_mymodule.xml</filename>
        <folder>tmpl</folder>
    </files>
    <config>
        <fields name="params">
            <fieldset name="basic">
                <field
                    name="param1"
                    type="text"
                    default=""
                    label="Parameter 1"
                    description="This is a Parameter 1 description">
                </field>
                <field
                    name="param2"
                    type="text"
                    default=""
                    label="Parameter 2"
                    description="This is a Parameter 2 description">
                </field>
 
            </fieldset>      
            <fieldset
                name="advanced">
                <field
                    name="layout"
                    type="modulelayout"
                    label="JFIELD_ALT_LAYOUT_LABEL"
                    description="JFIELD_ALT_MODULE_LAYOUT_DESC" />
                <field
                    name="moduleclass_sfx"
                    type="text"
                    label="COM_MODULES_FIELD_MODULECLASS_SFX_LABEL"
                    description="COM_MODULES_FIELD_MODULECLASS_SFX_DESC" />
                <field
                    name="owncache"
                    type="list"
                    default="1"
                    label="COM_MODULES_FIELD_CACHING_LABEL"
                    description="COM_MODULES_FIELD_CACHING_DESC">
                    <option
                        value="1">JGLOBAL_USE_GLOBAL
                    </option>
                    <option
                        value="0">COM_MODULES_FIELD_VALUE_NOCACHING
                    </option>
                </field>
            </fieldset>                   
        </fields>
    </config>
</extension>
 

file helper.php

View source
<?php
 
// My first module in joomla 2.5
// www.developerpages.gr
 
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
<?php
// My first modyle in Joomla 2.5
// www.developerpages.gr
 
//no direct access
defined('_JEXEC') or die('Restricted access');
 
//include the syndicate functions only once
require_once(dirname(__file__).DS.'helper.php');
 
// Load helper class and functions
$message = modMyModuleHelper::getMessage($params);
 
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
 
// Load layout filefrom template views
require(JModuleHelper::getLayoutPath('mod_mymodule'));
 
?>
 

file tmpl\index.html

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

file tmpl\default.php

View source
<?php
// My first module in joomla 2.5 
// www.developerpages.gr
 
// no direct access
defined('_JEXEC') or die('Restricted access !');
 
echo $message;
 
?>
 

we make the mod_mymodule.zip 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

   

Login  

   
   

     

© Developerpages