How to Create a Component/Module for Joomla
Cannot find the component/module that completely meets your requirements within the standard Joomla extensions? Then create it by yourself! In this article I will tell you a simple way to create a unique Joomla extension.
Create a component
Of course, you should have some programming skills to create a difficult component. But writing of php code is not the point of this article. I would like to focus on how it works in Joomla here.
So, in the root folder of your site, navigate to the components folder and create there a folder named as com_myscript (com_ is compulsory prefix and myscript – name of your component). Then create myscript.php file and put it into that folder. When done, you’ll have the .php file with the following path:
../components/com_myscript/myscript.php
Open the file and insert a simple php code there. For example,
<?php
# my script
echo "Hello World!";
?>
Save myscript.php. Your component is ready!
Create a module
Process of creating a new module is similar to creating of the component.
Create mod_ myscript folder within the ../modules/ in the root of your site and put mod_myscript.php file there. As usual, mod_ is compulsory prefix, and myscript is a name of new module. The path to your script should look like:
../modules/mod_myscript/mod_myscript.php
Insert php code into the file and save it.
Then create mod_myscript.xml file and place it at the same folder:
../modules/mod_myscript/mod_myscript.xml
You can use .xml file for some other module as an example. The necessary content of this file would be like the following:
<?xml version="1.0" encoding="utf-8" ?>
- <install type="module" version="1.5.0">
<name>Login</name>
<author>Joomla! Project</author>
<creationDate>October 2009</creationDate>
<copyright>Copyright (C) 2005 – 2008 Open Source Matters. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>1.5.0</version>
<description>DESCLOGINFORM</description>
- <files>
<filename module="mod_myscript">mod_myscript.php</filename>
</files>
</install>
Save the file and enjoy! Your module is ready.
Run the script
So, you have the required component/module. How you can run the script? Very simple – in the address bar of your browser, add /index.php?option=myscript to the URL of your site. Now the URL looks like:
http://mysiteaddress//index.php?option=myscript
You can run any script from your site in such way.