Creating a simple module
(Redirected from Talk:How to create a module)
It'd be nice if someone could modify this page and add explanations of some of the code. Most of the time the author assumes you should just work it out or something, not very helpful. For instance, what is jtext, what is JModuleHelper::getLayoutPath? There is basically two lines for each block of code at the moment.
Uh...ok, wow. I don't dare try to modify the main page as I'm absolutely a greenhorn at Joomla, but as I'm absolutely needing to know this information like right now, I'll at least add comments here to help the next guy out.
So, to get started, you can look at the previous version of Joomla to get the ball rolling. A link can be found here: Module Creating a simple module
Basically, things have changed a bit since that version, so you need to create two files modulename.php and modulename.xml
the PHP file starts like this:
<?php /** * @version $Id: modulename.php 10079 date time author $ * @package Joomla * @copyright Copyright (C) whoever. All rights reserved. * @license GNU/GPL, see LICENSE.php * See COPYRIGHT.php for copyright notices and details. */ // no direct access defined('_JEXEC') or die('Restricted access');
Then lays out the code for whatever the module is trying to do.
The XML file follows the following format:
<?xml version="1.0" encoding="utf-8"?> <install type="module" version="1.5.0"> <name>Modulename</name> <author>Your Name</author> <creationDate>Date</creationDate> <copyright>Copyright (C) whoever. All rights reserved.</copyright> <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license> <authorEmail>firstname.lastname@example.org</authorEmail> <authorUrl>your.website.address</authorUrl> <version>1.5.0</version> <description>This module does whatever function you describe here</description> <files> <filename module="modulename">modulename.php</filename> </files> <params> <param name="something" type="whatever" > <option value="1">option 1</option> <option value="0">option 2</option> </param> </params> </install>
The params section is optional.
Once these files are created, you have to place them where either your web browser or your server can get to them, and then use the Joomla Administrator panel to install the module. This creates the necessary database rows to serve the module where you need it to function.