Create you first Joomla 1.6 module completely from scratch.
Joomla, as of version 1.5 which was a complete rewrite is based on the MVC design pattern which makes creating modules extremely easy and structured. Joomla 1.6 changes a few things, the basics however remain the same.
- Create a folder called mod_helloworld in modules
- Create a mod_helloworld.php file
- Create a mod_helloworld.xml file
- Create a helper.php file
- Create a template file tmpl/default.php
- Discover new modules by going to “Extension Manager” -> “Discover”
The code for mod_helloworld.php
<?php defined('_JEXEC') or die; // no direct access allowed require_once dirname(__FILE__).DS.'helper.php'; // get helper files $hello = modHelloWorldHelper::getHello($params); require JModuleHelper::getLayoutPath('mod_helloworld'); ?>
The helper.php file
<?php class modHelloWorldHelper { /** * Retrieves the hello message * * @param array $params An object containing the module parameters * @access public */ function getHello( $params ) { return 'Hello, World!'; } } ?>
Include the template file for the default view
<?php defined('_JEXEC') or die; echo $hello; ?>
The helloworld.xml file
<?xml version="1.0" encoding="utf-8"?> <extension type="module" version="1.6.0" client="site" method="upgrade"> <name>Hello World!</name> <author>Reinhold Weber</author> <version>1.6.0</version> <description>Reinholds simple Hello World module.</description> <files> <filename module="mod_helloworld">mod_helloworld.php</filename> <filename>mod_helloworld.xml</filename> <filename>index.html</filename> <filename>helper.php</filename> <filename>tmpl/default.php</filename> <filename>tmpl/index.html</filename> </files> <params> </params> </extension>
Create both index.html files to prevent direct directory browsing
<html><body></body></html>
Sorry to say that … your xml file is not correct.
The “param”, “params” tags are deprecated.
The param tags for the configuration are called
* fields
* fieldset
* field
And what is also correct in your xml, install is now extension.
greatings,
Daniel
Yes, Daniel Böttner is correct in stating that “params” and “param” tag has been deprecated
+ this would not work on 1.6.
But this is by far the most informative introduction to creating your own module; perhaps there are others but I haven’t found one yet.
Kudos to you Reinhold Weber.
Regards,
Zaki
Hi
Like this tutorial it’s very good.
Would you let me know please how can I convert a current Joomla 1.5 module into and joomla 1.6 module?
What has to be updated?
Many Thanks for the great tutorial and Kind Regards
Charles
Can you post any information on how to convert a Joomla 1.5 module to 1.6?
Thank you
very informative.. but param is deprecated.. nonetheless informative tutorial
Hello there. this is just what i needed to start programming joomla. However I have uploaded ti and it doesn’t work, it wont show up in ‘discover’ mode and it wont install when i zip it up and do it the conventional way.
This is the error I get when I try to install:
* Failed loading XML file
* /home/jtperfo1/public_html/tmp/install_4d60904560437/mod_homegrid/mod_homegrid.xml
* XML: XML declaration allowed only at the start of the document
* JInstaller: :Install: Cannot find Joomla XML setup file
In discover mode, nothing happens. Please help.
Thanks, James
mod_helloworld.xml
{No gaps}
Mmm XML file not correct bro. Param -> field .. etc
Discover!!!!!
Thanks a lot! I could lose the whole day looking for this function!
Hi,
I cant make module working. I can’t install. I have the same mistake as James.
This is the error I get when I try to install:
* Failed loading XML file
* /home/jtperfo1/public_html/tmp/install_4d60904560437/mod_homegrid/mod_homegrid.xml
* XML: XML declaration allowed only at the start of the document
* JInstaller: :Install: Cannot find Joomla XML setup file
I don’t understand what did Zubar mean with {No gaps}.
Thanx for the help.
Got same mistakes…
[...] estava trabalhando em uma lista de “pecados” para programadores PHP, mas o Reinhold Weber se adiantou. Melhor, porque a lista dele é bem maior que a minha Resolvi fazer uma tradução [...]
It means that when you copied the xml code to your local file, there was gaps or space or tabs in front of the beginning of the code you copied.
Remove all gaps before the opening <?xml
and you will be fine.
I have created all files mentioned. can u help me how to use that module?
I created all files. Joomla discovered the Module but the Module Manager doesn’t show it up. Where is the module gone?
Its not working. Even not visible is module portion. Any suggestions.?
Thanks.
It works
Though I have to change some of your code
In this line of the .xml file
makes sure the version matches the joomla version of your site.
Good tutorial. Was very helpful. Thanks.
Sorry, auto correct removed the code line:
make sure — version=” 1.6.4″ — in the extension tag matches the version of your joomla install.
Nice!
I made this for joomla 1.7 a few days ago, it’s a bit extended
http://trikks.wordpress.com/2011/10/06/joomla-1-7-hello-world-module-evolved/
Cheers
Heya i am for the primary time here. I came across this board and I find It really useful & it helped me out a lot. I am hoping to offer something back and help others like you helped me.
Hi, i feel that i saw you visited my website thus i came to ?go back the favor?.I am attempting to in finding issues to improve my website!I assume its adequate to use some of your concepts!!
Fantastic beat ! I wish to apprentice while you amend your web site, how could i subscribe for a weblog web site? The account helped me a appropriate deal. I were tiny bit familiar of this your broadcast offered shiny clear idea
It’s the best time to make some plans for the long run and it is time to be happy. I’ve learn this post and if I may just I desire to suggest you some interesting things or advice. Perhaps you can write subsequent articles regarding this article. I desire to read even more things about it!
Thanks for the tutorial, would you let me know please,
how would you add css and jquery to a module?
Many Thanks
I just like the helpful information you provide for your articles. I’ll bookmark your weblog and test once more right here regularly. I’m relatively certain I’ll be told plenty of new stuff right here! Best of luck for the next!
u r so good programmer..
any extra topics link send my email id.