Creating a Joomla module

Share this post on:

Files to create / Update

Create  mod_breed.xml /modules/mod_breed/mod_breed.xml

Create  mod_breed.php /modules/mod_breed/mod_breed.php

Create  default.php /modules/mod_breed/tmpl/default.php

Create  en-GB.mod_breed.ini  /language/en-GB/en-GB.mod_breed.ini

Create  en-GB.mod_breed.sys.ini  /language/en-GB/en-GB.mod_breed.sys.ini

 

Files Details

 /modules/mod_breed/mod_breed.xml

 <?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="3.1" client="site" method="upgrade">
	<name>BREEDS</name>
	<author>Nohman Habib</author>
	<creationDate>July 2016</creationDate>
	<copyright>Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.</copyright>
	<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
	<authorUrl>www.codingace.com</authorUrl>
	<version>3.0.0</version>
	<description>BREEDS_MODULE_DESC</description>
	<files>
		<filename module="mod_breed">mod_breed.php</filename>
		<folder>tmpl</folder>
	</files>
	<languages>
		<language tag="en-GB">en-GB.mod_breed.ini</language>
		<language tag="en-GB">en-GB.mod_breed.sys.ini</language>
	</languages>

	<config>
		<fields name="params">
			<fieldset name="basic">


				<field
					name="width"
					type="text"
					default="200"
					class="validate-numeric"
					filter="integer"
					label="MOD_BREED_IMAGE_WIDTH_LABEL"
					description="MOD_BREED_IMAGE_WIDTH_DESC" />


				<field
					name="height"
					type="text"
					default="200"
					class="validate-numeric"
					filter="integer"
					label="MOD_BREED_IMAGE_HEIGHT_LABEL"
					description="MOD_BREED_IMAGE_HEIGHT_DESC" />

			</fieldset>
		</fields>
	</config>
</extension>

/modules/mod_breed/mod_breed.php


<?php

defined('_JEXEC') or die;

$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8');

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

/modules/mod_breed/tmpl/default.php

<?php

defined('_JEXEC') or die;

$width      = $params->get('width');
$height    = $params->get('height');

    $query = "SELECT * FROM #__breed_breed ORDER BY rand() LIMIT 1 "; 
    $db = &JFactory::getDBO();
    $db->setQuery($query);
    $rowsc = $db->loadObjectList();
    foreach($rowsc as $rowc) 
{ 
 $breedname=$rowc->breedname;   $pic=$rowc->pic;   $shortdesc=$rowc->shortdesc;
 }

?>

<h4><?php echo $breedname; ?></h4>

<img src="<?php echo JRoute::_(JUri::root()); ?>/components/com_breed/breedpic/<?php echo $pic; ?>" width="<?php echo $width; ?>px" height="<?php echo $height; ?>px">

<p>
<?php echo $shortdesc; ?>
</p>

/language/en-GB/en-GB.mod_breed.sys.ini

BREEDS="Breeds"

 /language/en-GB/en-GB.mod_breed.ini

BREEDS="Breeds"
BREEDS_MODULE_DESC="Displays random breeds from breeds component"
MOD_BREED_IMAGE_WIDTH_LABEL="Image width (px)"
MOD_BREED_IMAGE_HEIGHT_LABEL="Image height (px)"
Share this post on:

Author: Nohman Habib

I basically work in the CMS, like Joomla and WordPress and in framework like Laravel and have keen interest in developing mobile apps by utilizing hybrid technology. I also have experience working in AWS technology. In terms of CMS, I give Joomla the most value because I found it so much user freindly and my clients feel so much easy to manage their project in it.

View all posts by Nohman Habib >

Leave a Reply

Your email address will not be published. Required fields are marked *

PHP Code Snippets Powered By : XYZScripts.com