Searching...
Thursday, September 12, 2013

How to write a joomla module in Joomla2.5


How to write a joomla custom module in Joomla2.5

A Joomla! module is a light-weight and flexible extension that is used for page rendering. They’re used for little bits of the page that are usually less complex and are able to be seen across totally different components.

File Structure:

There are two folder and three files in root (mod_xyz) folder and in the language folder again a subfolder en-GB, in this folder it holds two files en-GB.mod_xyz.ini and en-GB.mod_xyz.sys.ini. In the tmpl folder, it holds default.php.    

 

(For Example we used name:  mod_xyz)
  1. helper.php:- This file contains the helper class which is used to do right work in retrieving the information to be displayed in the module
  2. mod_xyz.php:- This file is a main file of module. It will perform all necessary initialization routines; we can call all helper routines in this file as well as we call all necessary data in this file. We can call and include the template which will display the output of the module.
  3. mod_xyz.xml:- This file contains all information about the module. In this file, we define all files that need to be time for installation of module.
  4. tmpl->default.php:- This file found in tmpl folder in this module. That page is a structure of a display of module. This file takes data from mod_xyz.php and converted in to html and displays the output.
Two others files which is in language->en-GB folder
  1. en-GB.mod_xyz.ini and en-GB.mod_xyz.xys.ini files are languages files which are used to provide short name of any description or name etc.

Create a file mod_xyz.php:

     There are some task perform in mod_xyz.php
  1. Include helper.php file which contains the class to be used to collect the data.
  2. Invoke the helper class method to retrieve the data.
  3. Include the template to display the requirement output.
The helper file include by:

require_once dirname(__FILE__).'/helper.php';

The helper class method include by:

 require JModuleHelper::getLayoutPath('mod_xyz', $params->get('layout', 'default'));

Create a file default.php

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

 <?php
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
echo ”Hello xyz”;
?>


Create mod_xyz.xml

Module xyz.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 as well as other information about the module.
 
The code for mod_xyz.xml is as follows:
                   
 
<?xml version="1.0" encoding="utf-8"?>
         <extension
                    type="module"
                    version="2.5"
                    client="xyz"
                    method="upgrade"
         >
        <name>mod_xyz</name>
        <author>Click 4 Joomla</author>
        <creationDate>July 2013</creationDate>
       <copyright>Copyright (C) 2013 - 2015 click4joomla. All rights reserved. </copyright>
        <license>GNU General Public License version 2 </license>
        <authorEmail>info@click4joomls.com</authorEmail>
        <authorUrl>www. click4joomla.com </authorUrl>
        <version>2.5.0</version>
        <description>MOD_XYZ_XML_DESCRIPTION</description>
        <files>
                    <filename>mod_xyz</filename>
                    <filename module=” mod_xyz”>mod_xyz.php</filename>
                    <filename>index.html</filename>
                    <filename>helper.php</filename>
                    <filename>tmpl/default.php</filename>
                    <filename>tmpl/index.php</filename>
        </files>
       <languages>
                    <language tag="en-GB">en-GB.mod_xyz.ini</language>
                    <language tag="en-GB">en-GB.mod_xyz.sys.ini</language>
       </languages>
      <config>
      </config>
</extension>


Create a helper.php

The helper.php file contains helper class that is used to retrieve the data to be displayed in the module output. At the starts of class one method getXyz(). It will return the “Hello xyz” message

Create index.php

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

0 comments:

Post a Comment

 
Back to top!