Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
0Activity
0 of .
Results for:
No results containing your search query
P. 1
Creating a Hello World for Joomla 15

Creating a Hello World for Joomla 15

Ratings:

4.85

(13)
|Views: 6,553 |Likes:
Published by Ersun
Creating a Hello World component and module for Joomla 15
Creating a Hello World component and module for Joomla 15

More info:

Published by: Ersun on Jul 23, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

11/02/2012

pdf

text

original

 
Creating a Hello World Module for Joomla! 1.5
A module is a lightweight and flexible extension that is used for page rendering. They are used forsmall bits of the page that are generally less complex and are able to be seen across differentcomponents. You can see many examples of modules in the standard Joomla! install: - menus - Latest News -Login form - and many more. This tutorial will explain how to go about creating a simple Hello World module. Through this tutorialyou will learn the basic file structure of a module. This basic structure can then be expanded toproduce more elaborate modules.
File Structure
 There are four basic files that are used in the standard pattern of module development: *mod_helloworld.php - This file is the main entry point for the module. It will perform any necessaryinitialization routines, call helper routines to collect any necessary data, and include the templatewhich will display the module output.
mod_helloworld.xml - This file contains information about the module. It defines the filesthat need to be installed by the Joomla! installer and specifies configuration parameters forthe module.
helper.php - This file contains the helper class which is used to do the actual work inretrieving the information to be displayed in the module (usually from the database or someother source).
tmpl/default.php - This is the module template. This file will take the data collected bymod_helloworld.php and generate the HTML to be displayed on the page.
Creating mod_helloworld.php
 The mod_helloworld.php file will perform three tasks:
include the helper.php file which contains the class to be used to collect the necessary data
invoke the appropriate helper class method to retrieve the data
include the template to display the output. The helper class is defined in our helper.php file. This file is included with a require_once statement:
require_once( dirname(__FILE__).DS.'helper.php' );
require_once is used because our helper functions are defined within a class, and we only want theclass defined once.Our helper class has not been defined yet, but when it is, it will contain one method: getHello(). Forour basic example, it is not really necessary to do this - the “Hello, World” message that this
 
method returns could simply be included in the template. We use a helper class here todemonstrate this basic technique.Our module currently does not use any parameters, but we will pass them to the helper methodanyway so that it can be used later if we decide to expand the functionality of our module. The helper class method is invoked in the following way:
$hello = modHelloWorldHelper::getHello( $params );
Completed mod_helloworld.php file
 The complete mod_helloworld.php file is as follows:
<?php/*** Hello World! Module Entry Point** @package Joomla.Tutorials* @subpackage Modules* @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:modules/* @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 accessdefined( '_JEXEC' ) or die( 'Restricted access' );// Include the syndicate functions only oncerequire_once( dirname(__FILE__).DS.'helper.php' );$hello = modHelloWorldHelper::getHello( $params );require( JModuleHelper::getLayoutPath( 'mod_helloworld' ) );
 The one line that we haven’t explained so far is the first line. This line checks to make sure that thisfile is being included from the Joomla! application. This is necessary to prevent variable injectionand other potential security concerns.
Creating helper.php
 The helper.php file contains that helper class that is used to retrieve the data to be displayed in themodule output. As stated earlier, our helper class will have one method: getHello(). This method willreturn the ‘Hello, World’ message.
 
Here is the code for the helper.php file:
<?php/*** Helper class for Hello World! module** @package Joomla.Tutorials* @subpackage Modules* @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:modules/* @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*/function getHello( $params ){return 'Hello, World!';}}
 There is no rule stating that we must name our helper class as we have, but it is helpful to do thisso that it is easily identifiable and locateable.More advanced modules might include database requests or other functionality in the helper classmethod.
Creating tmpl/default.php
 The default.php file is the template which displays the module output. The code for the default.php file is as follows:
<?php // no direct accessdefined( '_JEXEC' ) or die( 'Restricted access' ); ?><?php echo $hello; ?>

Activity (0)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Endless Love liked this
malaikkannan liked this
ALi liked this
yacaev liked this
sushiljsp liked this
Maliyala Kalidas liked this
raouldesjoints liked this
ysntechno liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->