User

Rvsjoen/tutorial/Developing a Module/Part 05: Difference between revisions

From Joomla! Documentation

Rvsjoen (talk | contribs)
Rvsjoen (talk | contribs)
Line 31: Line 31:
<span id="mod_helloworld.php">
<span id="mod_helloworld.php">
'''<tt>mod_helloworld.php</tt>'''
'''<tt>mod_helloworld.php</tt>'''
<source lang="php">
<source lang="php" highlight="13">
<?php  
<?php  


Line 54: Line 54:
<span id="mod_helloworld.xml">
<span id="mod_helloworld.xml">
'''<tt>mod_helloworld.xml</tt>'''
'''<tt>mod_helloworld.xml</tt>'''
<source lang="xml">
<source lang="xml" highlight="22">
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" method="upgrade">
<extension type="module" version="2.5.0" method="upgrade">

Revision as of 16:42, 13 March 2012

Adding a helper

With your favorite editor, create the following file

helper.php

<?php 

/**
 * @package	Joomla.Tutorials
 * @subpackage	Module
 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
 * @license	License GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access to this file
defined('_JEXEC') or die;

class modHelloWorldHelper
{
	public static function getGreeting() {
		return "Message from the helper";
	}
}

With your favorite editor, edit the following file

mod_helloworld.php

<?php 

/**
 * @package	Joomla.Tutorials
 * @subpackage	Module
 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
 * @license	License GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access to this file
defined('_JEXEC') or die;

JLoader::register('modHelloWorldHelper', JPATH_BASE.'/modules/mod_helloworld/helper.php');

require JModuleHelper::getLayoutPath('mod_helloworld', $params->get('layout', 'default'));

With your favorite editor, edit the following file

mod_helloworld.xml

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" method="upgrade">

	<name>MOD_HELLOWORLD</name>
	<!-- The following elements are optional and free of formatting constraints -->
	<creationDate>Once upon a time</creationDate>
	<author>John Doe</author>
	<authorEmail>john.doe@example.org</authorEmail>
	<authorUrl>http://www.example.org</authorUrl>
	<copyright>Copyright Info</copyright>
	<license>License Info</license>
	<!--  The version string is stored in the extension table -->
	<version>0.0.5</version>
	<!-- The description is optional and defaults to the name -->
	<description>MOD_HELLOWORLD_XML_DESCRIPTION</description>

	<!-- Note the folder attribute: This attribute describes what to copy
		into the module folder -->
	<files>
		<filename module="mod_helloworld">mod_helloworld.php</filename>
		<filename>mod_helloworld.xml</filename>
		<filename>helper.php</filename>
		<folder>tmpl</folder>
		<folder>language</folder>
	</files>

	<config>
		<fields name="params">
			<fieldset name="basic">
				<field
					name="greeting"
					type="text"
					default="MOD_HELLOWORLD_GREETING_DEFAULT"
					label="MOD_HELLOWORLD_GREETING_LABEL"
					description="MOD_HELLOWORLD_GREETING_DESC"
				/>
			</fieldset>
		</fields>
	</config>

</extension>

File listing

Download this part

To be continued...

Articles in this series

This tutorial is supported by the following versions of Joomla!

Joomla 2.5