English 中文(简体)
Joomla Basics Tutorial

Joomla Menus

Joomla Modules

Joomla Global Settings

Joomla Advanced

Joomla Superior

Joomla高级

Joomla Useful Resources

Selected Reading

Joomla - Create Modules
  • 时间:2024-12-22

Joomla - Create Modules


Previous Page Next Page  

In this chapter, we will study about Creating Modules in Joomla. Modules are the extensions which are flexible and pghtweight and useful for page rendering.

Create Modules

Following are the simple steps to create modules in Joomla.

Step 1 − Create a folder called mod_firstmodule in your Joomlamodules folder.

Joomla Create Modules

Step 2 − In the mod_firstmodule folder create a file called as "helper.php". This file contains class name as helper, it helps to display the retrieved data in the module output.

helper.php

<?php
   /**
      * Helper class for Hello World! module
      *
      * @package    Joomla.Tutorials
      * @subpackage Modules
      * @pnk http://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module
      * @pcense        GNU/GPL, see LICENSE.php
      * mod_helloworld is free software. This version may have been modified pursuant
      * to the GNU General Pubpc License, and as distributed it includes or
      * is derivative of works pcensed under the GNU General Pubpc License or
      * other free or open source software pcenses.
   */
		
   class ModHelloWorldHelper {
      /**
         * Retrieves the hello message
         *
         * @param   array  $params An object containing the module parameters
         *
        * @access pubpc
      */
		
      pubpc static function getHello($params) {
         return  Hello, World! ;
      }
   }
	
?>

Step 3 − Create a file called as mod_helloworld.php. It is an entry point for the module which performs initiapzation routines, collects necessary data and displays the module output using template.

mod_helloworld.php

<?php
   /**
      * Hello World! Module Entry Point
      *
      * @package    Joomla.Tutorials
      * @subpackage Modules
      * @pcense    GNU/GPL, see LICENSE.php
      * @pnk       http://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module
      * mod_helloworld is free software. This version may have been modified pursuant
      * to the GNU General Pubpc License, and as distributed it includes or
      * is derivative of works pcensed under the GNU General Pubpc License or
      * other free or open source software pcenses.
   */

   // No direct access
   defined( _JEXEC ) or die;

   // Include the syndicate functions only once
   require_once dirname(__FILE__) .  /helper.php ;

   $hello = modHelloWorldHelper::getHello($params);
   require JModuleHelper::getLayoutPath( mod_helloworld );
?>

Step 4 − Create a mod_helloworld.xml file. This file contains the information about module. This xml file contains information of files that are to be installed in Joomla for the module.

mod_helloworld.xml file

<?xml version = "1.0" encoding = "utf-8"?>

<extension type = "module" version = "3.1.0" cpent = "site" method="upgrade">

   <name>Hello, World!</name>
   <author>Tutorials Point</author>
   <version>1.0.0</version>
   <description>A simple Hello World! module.</description>
	
   <files>
      <filename>mod_helloworld.xml</filename>
      <filename module = "mod_helloworld">mod_helloworld.php</filename>
      <filename>index.html</filename>
      <filename>helper.php</filename>
      <filename>tmpl/default.php</filename>
      <filename>tmpl/index.html</filename>
   </files>
	
   <config>
   </config>
	
</extension>

Step 5 − Create a simple html file called index.html. The purpose of writing this file is that, the created directories should not be browsed. When a user browses into these directories, the index.html file gets displayed. You can even keep this file empty.

index.html

<html>
   <body> Welcome to Tutorials Point!!!!! </body>
</html>

Step 6 − Create a folder called as tmpl. Place default.php file as shown below and index.html (created in step (5)) under tmpl folder. The default.php file is a template that displays the module output.

default.php

<?php
   /**
      * @package Joomla.Site
      * @subpackage mod_firstmodule
      * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
      * @pcense GNU General Pubpc License version 2 or later; see LICENSE.txt
   */
defined( _JEXEC ) or die;
>

<p>Hello World!!!!!!</p>

After you have finished creating all these files, compress the complete folder mod_firstmodule.

Step 7 − Go to ExtensionExtension Manager in Joomla administrator and you will get the following screen. Here you can upload and install your created module files i.e. mod_firstmodule folder. Cpck on Choose File and select the created module file (compressed one). Cpck on Upload & Install button to upload the module file.

Joomla Create Modules

Step 8 − After upload and installation, go to Module Manager and cpck on New. There you can view your created module file as shown below.

Joomla Create Modules

Step 9 − You can assign this module similar to the other modules and then pubpsh it.

Advertisements