Take the 2-minute tour ×
Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It's 100% free, no registration required.

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!

share|improve this question

4 Answers 4

up vote 10 down vote accepted

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:

  1. mod_articles_latest.php
  2. helper.php
  3. tmpl/default.php
  4. mod_articles_latest.xml

    1. The 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.

    2. The 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 : getList(&$params).

      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.

    3. The 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.

    4. Finally, the 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.

share|improve this answer

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.
share|improve this answer
    
that answers my use-case wrt php, but it doesn't answer what I was actually asking (in my case, I need to save certain settings like color etc. for each use of the module, which will be easier if I can create a new module rather then just access php) though thanks for the tip. –  serakfalcon May 7 at 4:25
    
You can add more parameters to the module and use these params in your php files. –  Shyam May 7 at 4:29

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?

share|improve this answer
    
That works to a degree, and it's often the way I start, but is insufficient to deal with language strings and additional media which gets installed into different locations. –  Peter Wiseman May 7 at 7:20
    
@PeterWiseman Yes, you are right, but it is an easy and fast way to get started. –  seagul May 7 at 8:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.