Showing posts with label Joomla Module Development. Show all posts
Showing posts with label Joomla Module Development. Show all posts

Friday, September 13, 2013

How to write a joomla module in Joomla2.5 with video


How to write a joomla module development  in Joomla2.5 with video

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.

Folder Structure:

Let’s we take module name – mod_latest
Module->mod_latest
  • mod_latest.php
  • mod_latest.xml
  • helper.php
  • index.html
  • tmpl/default.php
  • tmpl/index.php

mod_latest.php

<?php
//license details here
 
//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 funtion
       $latest = modLatestHelper::getLatest($params);
//load the layout file from template views
       Require(JModuleHelper::getLayoutPath(‘mod_latest’)); 
 ?>
 
defined(‘_JEXEC’) or die(‘Restricted access’);
 
This line checks to make sure that this file is being included from the joomla! Application. It’s necessary to prevent variable injection and other security.
 
require_once(dirname(__FILE__).DS.’helper.php’);
 
The helper class is defined in our helper.php file. This file is included with a require_once statement. It allows including necessary functions for the module functionality. Heper file calculations, DB connection and query code.
 
$latest = modLatestHelper::getLatest($params);

It is allows to invoke the appropriate helper class method to retrieve the data.

require(JModuleHelper::getLayoutPath(‘mod_latest’));
It includes the template to display the output

mod_latest.xml

  <?xml version="1.0" encoding="utf-8"?>
         <extension
                    type="module"
                    version="2.5"
                    client="click4joomla"
                    method="upgrade"
         >
        <name>mod_latest</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. click4joomls.com </authorUrl>
        <version>2.5.0</version>
        <description>MOD_LATEST_XML_DESCRIPTION</description>
        <files>
                    <filename>mod_latest</filename>
                    <filename module=” mod_ latest”>mod_ latest.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_ latest.ini</language>
                    <language tag="en-GB">en-GB.mod_ latest.sys.ini</language>
       </languages>
      <config>
      </config>
</extension>

(This file 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)

helper.php

<?php
   //license details here
class modLatestHelper
{
                function getLatest($params)
                {
                                Return ‘I am Raghvender Singh’;
                 }
}
?>

index.html This file is included to prevent directory browsing. It can be event left blank and whenever someone will access the directory then this file will be default loaded. default.php


 

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>