Pages

Friday, September 21, 2012

Create a Custom Joomla 2.5 Module step by step guide


The focus of this course, is to Create a Custom Joomla 2.5 Module step by step guides. I hope You have already learned  Joomla Installation , Create a  Joomla Hello world Components  from this blogs. Let we start our new Joomla CMS Custom Module Course Here, 

There is a defined folder structure for Joomla extension. Create the files and folders as per the below using your code editor. 

Create the main folder which will be called  "mod_siteusers". Then create the files/folders below.


Important: As per the Joomla extension, the mod_siteusers folder needs to be in your Joomla sites "Modules" folder BUT do not put it there yet because we need to create everything first then pack it in a zip file to install via Joomla admin area.

below the file strcture need to be create for out Joomla Module (mod_siteusers)

-mod_siteusers.xml
-mod_siteusers.php
-helper.php
-index.html
--tmpl (folder)
--tmpl/default.php
--tmpl/ordered_list.php
--tmpl/index.html

Okay, lets begin with carefully 

mod_siteusers.xml

This file holds all of the modules metadata, information and parameters. The file structure must be exact.




Site Users 
Krish 
2012 
All rights reserved by PHP CMS JOBS. 
GPL 2.0 
krishblogs2012@gmail.com 
www.php-cms-jobs.blogspot.in 
1.0.0 
Provides a listing of registered users
   

       
mod_siteusers.php
index.html
helper.php
tmpl/default.php
                tmpl/ordered_list.php
tmpl/index.html

       
        en-GB.mod_siteusers.ini
   

   

           
               
                   
                        name="moduleclass_sfx" 
                        type="text" 
                        default="" 
                        label="LABEL_CLASS_SUFFIX" 
                        description="DESC_MOD_SUFFIX">
                   
                     
                        name="@spacer" 
                        type="spacer" 
                        default="" 
                        label="" 
                        description="">
                   
                     
                        name="usercount" 
                        type="text" 
                        default="5" 
                        label="LABEL_USER_COUNT" 
                        description="DESC_USER_COUNT">
                   
                     
                        name="layout" 
                        type="list" 
                        default="default" 
                        label="LABEL_USER_LAYOUT" 
                        description="DESC_USER_LAYOUT">
                       
value="default">Unordered List

value="ordered_list">Ordered List
                   
               
           
   



you can update with your own personal info on " tags.

These are the parameters that are on the right hand side when viewing your module in modlue manager. Here we have 4. 

The first is the "module class suffix" which all modules have. The suffix the user adds here will be attached to the modules css class so you can style individual modules. The second is just a simple "spacer". The third is the number of users you wish to display in the module and finally, the fourth is the layout option. 

You can have multiple layouts for one module. Each layout should go in the tmpl folder. Our 2 options here is the default, which is an unordered list with the "Website Users" description at the top. The ordered_list layout uses a numbered list and no description at the top. The changes are very subtle but I just wanted to show you a simple example.

Another thing you might be looking at is the uppercase constants like "LABEL_USER_COUNT". These are used with the language file that will be included later.

mod_siteusers.php

This file acts as a controller directing the functions and files


Create a Joomla Custom Module 1


helper.php


Create a Joomla Custom Module 2


This file runs the main function (getItems). This function gets the users from the database using a specified query. Joomla has a very specific syntax for interacting with the database. You can read all about it here. The code above instantiates a database object, puts the query in a variable called $query, runs the query and returns the $items as an array. The query is self explanatory. It will select the id and the username from the users table and it will be limited buy $usercount which we specify in mod_siteusers.xml. This query will be used to loop through the array of users in default.php (view file).

index.html



This html file is strictly used to prevent users from accessing the module files directly

tmpl/default.php




The default.php file is the modules "default view". It is in charge of displaying the module to the user. It is essentially html with php includes and loops. This file performs a foreach loop to diaplay the $rows array which is the array of users.

tmpl/ordered_list.php





This is the "ordered list" layout. As stated above, the only difference is that it uses a numbered list and has no description parameter.

tmpl/index.html



Same as above, it is used to prevent users from accessing the module files directly

Now that all of your files are created, add the entire "mod_siteusers" folder to a zip file using whatever zip program you use (winzip, winrar, 7zip, etc).


Congrats! Your first Joomla module is complete.Lets Start your Work on Admin Panel


Login to your Joomla admin area and goto the extension manager. From the "install" seciton, browse and upload the zip file. You should get a "Successful Install" message.




Now go to the "Module Manager" and you should see your module. click on the title. Now you should see the properties of the module. You should see all your parameters on the right hand side. You can change the number of users to be displayed as well as the layout. Now make sure it is published and use the desired module position in your template.




Visit your frontend and you should see a list of your website users.



Congratulations, you have successfully Completed Create a Custom Joomla 2.5 Module Course, Now you can play around with Joomla Custom Modules..to know more about Drupal and other PHP related CMS, subscribe with us...



Related Posts




5 comments:

  1. Excelent content! Did you know about this tool? http://www.notwebdesign.com/joomla-component-creator/ What do you think about it? =)

    ReplyDelete
    Replies
    1. Thanks for your comments, yep i heard about it and i have seen it. This site helps to developer to create a component wihtin short time with some limition of the table creations (Free version). Thats it...

      Delete
  2. http://www.techguywebsolutions.com/create-a-custom-joomla-2.5-module.html
    is this is your own tutorial or just copied from the link i mentioned?

    ReplyDelete
  3. please can you help me in integrating my php application

    ReplyDelete
  4. Please help ma. I have a error.Please give me xml.Please.

    ReplyDelete