Searching...
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


 

0 comments:

Post a Comment

 
Back to top!