User talk


From Joomla! Documentation

Creating MW Module for Joomla 2.5 with Mehta Websolution[edit]

A module is a lightweight and flexible extension that is used for page rendering. They are used for small bits of the page that are generally less complex and are able to be seen across different components.

You can see many examples of modules in the standard Joomla! install: - menus - Latest News - Login form - and many more.

This tutorial will explain how to go about creating a simple Hello World module. Through this tutorial you will learn the basic file structure of a module. This basic structure can then be expanded to produce more elaborate modules.

File Structure[edit]

There are four basic files that are used in the standard pattern of module development:

  • mod_mw_okie_dude.php - This file is the main entry point for the module. It will perform any necessary initialization routines, call helper routines to collect any necessary data, and include the template which will display the module output.
  • mod_mw_okie_dude.xml - This file contains information about the module. It defines the files that need to be installed by the Joomla! installer and specifies configuration parameters for the module.
  • tmpl/default.php - This is the module template. This file will take the data collected by mod_mw_okie_dude.php and generate the HTML to be displayed on the page.

Creating mod_mw_okie_dude.php[edit]

The complete mod_mw_okie_dude.php file is as follows:

 * @module MW Okie Dude - Joomla 2.5 Module
 * @author Nirav Mehta ( Mehta Websolution ) 
 * @companyname Mehta Websolution
 * @link
 * @package    Mehta Websolution - Joomla Tutorials
 * @subpackage Modules
 * @link,com_jd-wiki/Itemid,31/id,tutorials:modules/
 * @license        GNU/GPL, see LICENSE.php
 * mod_mw_okie_dude is free software. developed by 
 * This version may have been modified pursuant.
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.

// no direct access
defined( '_JEXEC' ) or die;

require JModuleHelper::getLayoutPath('mod_mw_okie_dude');


The one line that we haven’t explained so far is the first line. This line checks to make sure that this file is being included from the Joomla! application. This is necessary to prevent variable injection and other potential security concerns.

Creating tmpl/default.php[edit]

The default.php file is the template which displays the module output.

The code for the default.php file is as follows:

 // no direct access
 defined( '_JEXEC' ) or die; 

<p><?php echo $params->get('mw_okie_dude_message'); ?></p>

An important point to note is that the template file has the same scope as the mod_mw_okie_dude.php file. What this means is that the variable $message can be defined in the mod_mw_okie_dude.php file and then used in the template file without any extra declarations or function calls.

Creating mod_mw_okie_dude.xml[edit]

The mod_mw_okie_dude.xml is used to specify which files the installer needs to copy and is used by the Module Manager to determine which parameters are used to configure the module. Other information about the module is also specified in this file.

The code for mod_mw_okie_dude.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" client="site" method="install">
	<name>MW Okie Dude</name>
	<author>Nirav Mehta</author>
	<creationDate>April 2012</creationDate>
	<copyright>Copyright (C)2012 Mehta Websolution</copyright>
	<license>GNU General Public License version 2 or later</license>
	<description>A module listing all of the activities developed by Mehta Websolution (</description>
		<filename module="mod_mw_okie_dude">mod_mw_okie_dude.php</filename>
		<filename>css/mw_okie_dude.css</filename> // here you can put your CSS code or Add your owned CSS file name //
		<filename>js/mw_okie_dude.js</filename> // here you can put your JS(Jquery)  code or Add your owned JS(Jquery) file name //

		<fields name="params">
			<fieldset name="basic">
					default="MW Okie Dude"
					description="Message to display above activity list" />

For a more complete example of an extension definition in XML, see Components:xml_installfile. Manifest_files explains the technical details of the elements used in the XML file.

You will notice that there are five additional files that we have not yet mentioned: index.html, css/index.html, images/index.html, js/index.html, tmpl/index.html. These files are included so that these directories cannot be browsed. If a user attempts to point their browser to these folders, the index.html file will be displayed. These files can be left empty or can contain the simple line:

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

which will display an empty page.

Since our module does not use any parameters, this section is empty.


Module development for Joomla2.5 . Using the techniques described in this tutorial, an endless variety of modules can be developed with Ravi Mehta.

Company : Mehta Websolution | Link : | Authors : Nirav Mehta & Ravi Mehta | City : Jamnagar | Country : India

Follow us on Facebook : Mehta Websolution | Nirav Mehta | Ravi Mehta

Category:Tutorials Module Category:Extension_development Category:Module Development Category:Module Category:Development Category:Main_Page Category:Joomla!_1.7 Category:Joomla!_2.5