Find us on facebook

Jun 16, 2015

Create simple module with Joomla 2.5

Step 1: Create folder and name it as mod_helloworld

Step 2: Create folder tmpl under mod_helloworld

Step 3: Create mod_helloworld.php under  mod_helloworld

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

// 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 helper.php under  mod_helloworld
<?php
/**
 * Helper class for Hello World! module
 *
 * @package    Joomla.Tutorials
 * @subpackage Modules
 * @link docs.joomla.org/J2.5:Creating_a_simple_module/Developing_a_Basic_Module
 * @license        GNU/GPL, see LICENSE.php
 * mod_helloworld is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 */
class ModHelloWorldHelper
{
    /**
     * Retrieves the hello message
     *
     * @param array $params An object containing the module parameters
     * @access public
     */  
    public static function getHello( $params )
    {
        return 'Hello, World!';
    }
}
?>

Step 5: Create mod_helloworld.xml under  mod_helloworld
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" client="site" method="upgrade">
    <name>Hello, World!</name>
    <author>John Doe</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 6: Create default.php under  mod_helloworld/tmpl
<?php
// No direct access
defined('_JEXEC') or die; ?>
<?php echo $hello; ?>

Step 7: Put  mod_helloworld under joomla/tmp (To install the module)

Step 8 : Go to Extensions->Extension manager

Step 8 : Go to Extensions->Module Manager
Configure module position


No comments:

Post a Comment