More Advanced Joomla Modules with PHP and Eclipse |
Written by Administrator | |||
Wednesday, 11 November 2009 | |||
Page 2 of 2
The Helper and the templateNow that we have the entry point complete we need to define the helper. This simply returns the "hello world" string or whatever data you really want in a real module: <?php Of course the class has to be called mymoduleHelper because that’s the name you use in the entry module and similarly the method has to be getHello - this is an interaction that you create. You should be able to see how it all fits together but feel free to do it a different way if you think that it is better. To try it all out create a new ZIP file containing all of the files including the XML file and install the module in the usual way - remembering to uninstall any earlier versions. (If you are unsure about how to do this refer to the article on Building a Joomla component .) Also remember to use the Module Manager to enable the module and assign it to a position on the page. When you look at one of your sites pages you should see the "Hello World" output as with the first version of the module. JModuleHelperA module has access to most of the basic facilities that the Joomla system provides - such as the database, parameters etc - and coding these facilities within a module is the same task as coding them into a component. The only unique element is the availability of the JModuleHelper class. This has a number of methods that allow you to work with modules from within your PHP code. You can use JModuleHelper from within a module to get details of the module or you can use it within general PHP code to load and run a module for whatever purposes you have in mind. As well as being a Joomla module a module is also a chunk of PHP code that can be executed in a different context - if you know how. JModuleHelper has four methods:
There is also a function
For example, suppose we want to process the output of the Breadcrumbs module. Then to test that it is enabled we could use: $state=JModuleHelper::isEnabled( Notice the use of all lower case - Breadcrumbs will fail to find the correct module. Assuming the Breadcrumbs module is enabled we can obtain the HTML it creates using: $mod1=JModuleHelper::getModule( Notice that this is the complete HTML that the module produces. Once you have seen JModuleHelper in action you should be able to think up interesting uses for it. Where next?The two main topics you need to study to write a more complex module or component are parameters and database access.
<ASIN:1847191304> <ASIN:143021628X> <ASIN:047043287X> |
|||
Last Updated ( Wednesday, 03 March 2010 ) |