Joomla Module

Embed Size (px)

Citation preview

  • 7/29/2019 Joomla Module

    1/6

    Creating the folder and file structure

    There is a strict file/folder structure when creating any kind of Joomla extension. Create the files and

    folders below using your favorite code editor or IDE. If you don't have this, use Notepa.. Create the main

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

    Important: In order for the module to work, 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.

    mod_siteusers

    -mod_siteusers.xml

    -mod_siteusers.php

    -helper.php

    -index.html

    --tmpl (folder)

    --tmpl/default.php

    --tmpl/ordered_list.php

    --tmpl/index.html

    Lets go through each file one by one...please read the comments in the code as well

    mod_siteusers.xml

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

    exact.

    Site Users

    Brad Traversy

    2012

    All rights reserved by Tech Guy Web Solutions.

    GPL 2.0

  • 7/29/2019 Joomla Module

    2/6

    [email protected]

    www.techguywebsolutions.com

    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

  • 7/29/2019 Joomla Module

    3/6

  • 7/29/2019 Joomla Module

    4/6

    label="LABEL_USER_LAYOUT"

    description="DESC_USER_LAYOUT">

    Unordered List

    Ordered List

    Feel free to change the personal info. One thing you should look at here is the " 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

    helper.php

    This is the main workhorse model that handles the business logic

  • 7/29/2019 Joomla Module

    5/6

    This file runs the query and selects the user "names" from the #__users table and limits the number of

    returned rows to whatever the user sets as the "user count" param from module manager. This query

    will then be loaded using the "loadObjectsList method and put in the $rows variable which we can now

    loop through in our default.php layout file below.

    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 try it out!

    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.

  • 7/29/2019 Joomla Module

    6/6

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