Monday, 24 May 2010 14:40

Creating a Joomla module

Written by Miguel
  • Print
  • E-mail
  • Share |
  • Be the first to comment!
joomlaA basic Joomla module consists of two files, a XML file and a PHP file. The XML file stores information about the module. This information is used by the Joomla installer to install the module, and display the module information in the module manager in the Joomla administration backend.

Additionally, the XML file can contain the module parameters which can be used to configure the module functionality. Below is an example of a XML file for a simple Joomla module:

<?xml version="1.0" encoding="utf-8"?>

<install type="module" version="1.5.0">

<name>My Module</name>

<author>Go Fish Client Catchers</author>

<creationDate>2010-04-20</creationDate>

<copyright>All rights reserved by Go Fish Client Catchers.</copyright>

<license>GPL 2.0</license>

<authorEmail> This e-mail address is being protected from spambots. You need JavaScript enabled to view it </authorEmail>

<authorUrl>www.gofishcc.com</authorUrl>

<version>1.0.0</version>

<description>A basic module to display a simple phrase</description>

<files>

<filename module="mod_mymodule">mod_mymodule.php</filename>

<filename>index.html</filename>

</files>

<params />

</install>



The XML file and the PHP file should have the same name (distinguished by their file extensions). In this case I will save the XML file as mod_mymodule.xml. Notice that in the XML file there is a reference to the PHP file entitled mod_mymodule.php. The PHP file contains the functional code defining the purpose of the actual module. Below is an example of the PHP file for the module:

<?php

defined('_JEXEC') or die('Direct Access to this location is not allowed.');

echo ‘This is my first module’;

?>



In this case, the module will simply display the phrase “This is my first module”.

A third file, index.html, is not necessary but is good practice as it ensures that a default page is displayed incase of a direct access attempt to the directory. The HTML file will look like this:

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



To package the module for installation and distribution, simply zip all the files, and name your zip file mod_mymodule.zip.
Last modified on Friday, 11 June 2010 09:45
Miguel

Miguel

E-mail: This e-mail address is being protected from spambots. You need JavaScript enabled to view it

Add comment



Call Us: +27 11 612 7460
LiveZilla Live Help