2. Basic knowledge of HTML, PHP and MySQL
Interest in MVC and CMS frameworks to reduce development
time
A web server with PHP/MySQL installed on it
Joomla! 2.5 package downloaded and installed
◦ it can be downloaded from http://www.joomla.org/download.html
NOTE: This presentation is focused for the beginners in Joomla! and would
cover only a basic overview due to limited time. Further details can be
discussed separately later.
4. Let’s create a module called “Reviews” for this
workshop which will display customer reviews
on the web page
It will allow us to display a simple text in a
pre-defined Joomla module position
Once this is done, we will fetch data for the
module from DB
6. <?php
//license details here
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'helper.php' );
//load helper class and function
$reviews = modReviewsHelper::getReviews( $params );
//load the layout file from template views
require( JModuleHelper::getLayoutPath( 'mod_reviews' ) );
?>
7. // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
As it suggests, this line checks to make sure that this
file is being included from the Joomla! application.
It is necessary to prevent variable injection and other
potential security concerns.
8. // Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'helper.php' );
The helper class is defined in our helper.php file.
This file is included with a require_once statement.
It allows to include necessary functions for the
module functionality. Helper file may include basic
calculations, DB connection and query code.
9. //load helper class and function
$reviews = modReviewsHelper::getReviews( $params );
This line allows to invoke the appropriate helper class method
to retrieve the data.
Currently, we do not use any parameters but it is allowed in this
module for future extensibility.
10. //load the layout file from template views
require( JModuleHelper::getLayoutPath( 'mod_reviews' ) );
This line includes the template to display the output.
11. <?xml version="1.0" encoding="utf-8"?>
<extension
type="module"
version="2.5"
client="site"
method="upgrade">
<name>Reviews</name>
<author>Vishwash Gaur</author>
<version>2.5.0</version>
<description>An review module.</description>
<files>
<filename module="mod_reviews">mod_reviews.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<folder>tmpl</folder>
<filename>mod_reviews.xml</filename>
</files>
</extension>
This file is used to specify which files the installer needs to copy
and is used by the Module Manager to determine which
parameters are used to configure the module.
12. <extension type="module“ version="2.5“
client="site“ method="upgrade">
This line tells to Joomla! that selected
extension type is module and compatible with
Joomla version 2.5.
Extension type is also defined for site which
means it will be available for front-end.
16. <?php
//license details here
class modReviewsHelper
{
/**
* Retrieves the reviews
*
* @param array $params An object containing the module parameters
* @access public
*/
function getReviews( $params )
{
return 'I am a happy user!';
}
}
?>
20. Once a base module is ready, we can start using it
immediately in Joomla.
In Joomla 1.5, it was auto-detected but in Joomla
2.5, we would need to discover a newly developed
extension from admin panel.
For this, please login to admin panel and go to Top
menu>extensions>extension manager
Click on the discover tab and refresh the data
24. If your programming is
correct, it will find your newly
developed extension.
Select the extension and click
on install button to setup the
extension.
25.
26. Once a module is added in the Joomla! System, it
has to be defined on a position using module
manager.
It will allow module to display in the front-end.
32. I can’t see the module
◦ Check if you have selected correct position in the
active template
33. With the previous example, you can display one
static customer review but what if there are many
customer reviews which should be dynamically
loaded on the page.
Let’s do that!
34. Using phpMyAdmin or any other DB management
tool, create a table called __reviews in the Joomla
DB
Add required fields i.e. id, name, city and feedback
in the table
Kindly note this example is meant to be very basic
for easy understanding
35. Create table and add
fields in the database.
Note: Ideally, it is the
part of component.
36.
37. I have done some entries in the DB directly
for the demo purpose. It should happen
via a back-end component in real
environment.
38. Now, since we are not doing any static code
and want to load reviews dynamically from
the database, we need to make some changes
in below files:
◦ mod_reviews.php – minor change
◦ helper.php – major change for DB connection and
query
◦ tmpl/default.php – minor change
◦ tmpl/reviews.php – new template file added
39. <?php
//license details here
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'helper.php' );
//load helper class and function
//$reviews = modReviewsHelper::getReviews( $params );
$rows = modReviewsHelper::getReviews( $params );
//load the layout file from template views
require( JModuleHelper::getLayoutPath( 'mod_reviews' ) );
?>
41. <?php
//license details here
class modReviewsHelper
{
/**
* Retrieves the reviews
*
* @param array $params An object containing the module parameters
* @access public
*/
function getReviews( $params )
{
return 'I am a happy user!';
}
}
?>
42. <?php
//license details here
class modReviewsHelper
{
/**
* Retrieves the reviews
* @param array $params An object containing the module parameters
* @access public
For the demonstration
*/
function getReviews( $params )
purpose, kindly understand
{
//return 'I am a happy user!';
and note that Joomla! uses
//limit the number of items to load from DB
$items = $params->get('items', 10);
it’s own code conventions
//make DB connection
to make DB connections and
$db=& JFactory::getDBO();
$result= null;
to run a query. It allows in
//run db query
$query = 'SELECT * FROM #__reviews';
less code and standardized
$db->setQuery($query, 0, $items);
$rows = $db->loadObjectList();
approach.
//display and handle error warning
if ($db->getErrorNum()) {
JError::raiseWarning( 500, $db->stderr(true) );
}
return $rows;
}
43. /**
* Function to display rating and reviews via views
* @param array $params An object containing the module parameters
* @access public
*/
function renderReviews(&$reviews, &$params)
{
//variable to store db value of a particular record link to open in detailed view
$link = JRoute::_('index.php?option=com_reviews&id='.$reviews->id.'&task=view');
//call template view for display
require(JModuleHelper::getLayoutPath('mod_reviews' , 'reviews'));
}
}
?>
This component doesn’t exists in the system but we have planned
it for future use or next demo of component development.
44. <?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
//print user reviews
//echo $reviews;
foreach($rows as $row)
{
modReviewsHelper::renderReviews($row, $params);
}
?>
47. Get your XAMP, LAMP, MAMP or WAMP environment
ready
Install and experiment Joomla! Locally
Checkout online references
Get a book
Visit Joomla! JED, Forums and user groups
Help each other and learn from experiences
48. I look forward to learn and share more with you in
future too.
I can be reached easily at my blog
www.vishwashgaur.com and/or using twitter
@vishwashgaur
Hi, I am Vishwash Gaur. Today, I am going to present a beginner series webinar on the topic of Component and Module development in Joomla 2.5
There would be an added benefit if you have downloaded, installed and used Joomla! a little bit in prior.In reducing the procedural code issues i.e. lack of code reusability, higher debugging time and more