How to develop a Joomla module plug-in
Clever architecture with M-V-C mechanisms
I have repeatedly stressed that Joomla! 1.5 is a very successful CMS developed with the MVC model. In addition to being the Control layer of the core system, other CMS can be expanded by developers themselves. Let's take a look at how it works.
In the past, I hope readers can have some basic php object syntax concepts, or take a relevant book at hand for reference at any time.
Module/mod_MyMod/mod_MyMod.xml
Modify the parameters in the previous registration installation file as follows:
<Params>
<Param name = "@ spacer" type = "spacer" default = "" label = "" description = ""/>
<Param name = "myParam" type = "text" default = "ha ?? Why? Where ?? Quot; label = "Hello everyone"
Description = "enter what you want to say"/>
</Params>
After the modification, the background management interface of the MyMod module is shown in the figure below. In the module Title column, enter the key [I have something to say], change the parameter field of [Hello everyone] to [glad to meet you].
Module/mod_MyMod/helper. php
This is an assisted file. We will write all the objects used in this module, so that this file is simple and only functional without considering typographical layout.
<? Php // no direct access
Defined ('_ JEXEC') or die ('restricted access ');
Class modMyModHelper {
// Create an implication to read the myParam parameter.
Function sayWords ($ params ){
Return $ params-> get ('myparam ');
}
}
?>
Module/mod_MyMod/mod_MyMod.php
The naming method of this file is principled. In addition to the same name as the module, the prefix (mod _) must be added. We will use helper in it. results generated by objects in the php file and stored in some variables.
Require_once (dirname (_ FILE _). DS. 'Helper. Php ');
This line is required. One-time introduction of the helper. php file helps the module operation.
<? Php
// No direct access
Defined ('_ JEXEC') or die ('restricted access ');
// Include the syndicate functions only once
Require_once (dirname (_ FILE _). DS. 'Helper. Php ');
// Define the show variable content as a sentence processed by the modMyModHelper object
$ Show = modMyModHelper: sayWords ($ params );
Require (JModuleHelper: getLayoutPath ('mod _ mymod '));
?>
Require (JModuleHelper: getLayoutPath ('mod _ mymod '));
This line is also required to use the JModuleHelper object of the Joomla system to tell the path of the system Layout file.
Module/mod_MyMod/tmpl/default. php
Finally, this file is the layout output (layout) of the entire module. Only when this file is written can we start to add HTML code.
<? Php
// No direct access
Defined ('_ JEXEC') or die ('restricted access ');
?>
<Div style = "background-color: # ccccff; display: block; height: 100px;">
<? Php echo $ show;?>
</Div>
If you are familiar with php, you can find that [helper. the name of the php] file can be customized. However, to have a good module architecture, we still follow the common development practices to avoid errors, second, people who take over can also get started in the shortest time to facilitate group development.
Finally, a simple module is complete. Is it very exciting!