For creating a module in joomla we need two types of file.
– PHP Scripts for business logic.
– XML File for installing the Module and providing any default or administrative value to business logic codes. Other CSS and image files can also be included but these are optional according to the need.
Easy Steps of creating a module
Step I : Create an XML file which contains the information of joomla as well as,
module which is going to be installed.
Step II : Write your business logic in PHP script which will commit your purpose.
Step III : Put all those files in a folder which should have the same name as defined in XML.
Step IV : Zip the folder with the same name using any zip application.
Now this module is ready to use, you can install it in your joomla application, you can create your module according to your need that can be for Joomla 1.0.x or Joomla 1.5.x
Things which are to be declared in XML file :
First line of XML:
<?xml version=”1.0″ encoding=”utf-8″ ?>
Second Line of XML :
<install type=”module” version=”1.5.0″>
Type : This should be declared as “Module”.
version : This is the place where you can put the value for which version of Joomla you are going to create a module.
<name>Name of Module </name>
<version>Version of Module</version>
<creationDate>Date of creation</creationDate>
<author>Name of Author</author>
<copyright>Put the copyright information here.</copyright>
<authorEmail>Here an author can put their Email-ID</authorEmail>
<authorUrl>If S/He want to put their website address </authorUrl>
<description>Put the description of the module.</description>
Above tags are used to put the information related to module and its author, and these are the sub tag of <install type=”module” version=”1.5.0″>.
Next tag is :
<filename>Folder name / filename.php</filename>
Next tag is :
<param name="parameter_name" type="input_type of parameter" default="put default value" label="Label of the parameter" description="Small description of parameter." />
Inside this XML tag (<params> </params>) you can put number of parameters according to your need.
Now close the tag <install> with </install>
Step II :
Start your PHP scripts
Put the first line as :
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
I think the purpose of the above line is very clear from its declaration, however, if you are still not sure then let me mention that the above line will restrict the user from direct access of your module.
If you are creating a module for Joomla 1.5.x then you can use the following line also:
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
How to get the value of parameters setted at backend :
$php_varable = $params->get( 'name_of_parameter_declared_in_XML' );
Now complete the PHP scripts as your requirement.
Put the files inside the folder and rename it as your module name.
Zip the folder using any application.