I've looked far and wide for a tutorial on this, but can't seem to find anything satisfactory. How do you make a new module for joomla?
Right now I'm using custom HTML modules all over my code, and I'd like to be able to reach into PHP and make them all into a module, but I haven't found a tutorial to do that. I've modified installed modules before but I don't know how to make one that will install.
The joomla documentation is quite confusing and after reading it through several times I gave up. Can anyone help explain this process to me? thanks!
We have developed a free module for the same purpose Custom PHP Module for Joomla CMS.
You need to create a PHP file e.g. login.php in [website-root]/modules/mod_customphp/files
- Now to use this file
- Go to [backend] -> module-manager
- Create new custom-php module
- In parameter includefile put login
- This will render login.php in module.
Have you seen the following tutorials in the joomla documentation?
In particular, make sure you look at all the articles in the series.
You can copy an existing module in a local installation. Then you rename it the way you want. You also have to rename the php and xml files as well as the php class names in the code. Then you just make a zip-file of your module. This zip-file you can install in your joomla installation.
Do you need more details about renaming?
The way I learned, was by studying and customizing the core or other 3rd party modules.
Modules as concept are simpler than the components (which we could say are 2 apps front-end/back-end) and are designed to display a piece of information.
So if you open the module folder/files and start reading the code, you will probably get fast into it.
For example, you can open the Latest Articles Module in Joomla 3.2 and check its code, while reading the lines below. In the module's folder we will find the 4 basic files:
mod_articles_latest.php is the main file of the modules, the one that is used first when the module is called. It initializes the module and includes the
helper.php, call the helper's class method to retrieve data and finally includes the template of the module (
default.php) to display the data.
helper.php file is the "machinery" of the module (if we could name it so). In the helper we create the module's class and its methods to retrieve the data. This is the place where we can have the module "talk" with the database. Reading the code in this module's helper file, you will see that it contains the
ModArticlesLatestHelper Class, which has one Method :
Within this method the module is checking for the backend settings of the module, and eventually build the list of the articles it will return, based on these conditions. Note that this module uses the
JModelLegacy::getInstance method to return the Content Model Object.
default.php is the main template of the module and responsible to display the module's content. - Here we build the html output, using the data you retrieved previously in the
mod_articles_latest.php by calling the module's class. It is located inside the tmpl folder. *Notice that the main module's file includes the template file with the
JModuleHelper::getLayoutPath method, which first will check for any template overrides.
mod_articles_latest.xml I would call it like the "ambassador" of the module. It is the file that "introduces" the module to Joomla during installation, it specifies the files that will be copied by the installer, and also contains the information about the parameters of the module that are used by the module manager, as well additional information about the module.
These are the essentials parts of a basic module. Another aspect you might want to consider is the support of multiple languages. This can be achieved by using Language Strings and Language Translation files. If you would have reached successfully that far, to create a basic module, then adding languages support should be pretty simple.