As you gain experience with procedural coding in PHP, you notice that there are tasks which are performed in a routine fashion and a lot of code which can be simply reused. What if you can save your time on these points using some of the existing PHP development frameworks and/or content management systems which allows MVC architecture and object oriented programming concepts to follow at ease for you?
In this beginner webinar on the topic, I would cover a quick introduction of content management system with focus on PHP based content management system “Joomla”. Joomla is considered as dynamic portal engine and content management system, and allows you to develop variety of systems from website, ecommerce store to a complex social network with the help of pre-built features i.e. caching, content management, web services, templates, and more.
The real power of Joomla lies in the scalability which can be achieved with the use of custom extensions which include templates, language files, plugins, modules and components. This webinar would further cover quick hands on workshop to download and setup Joomla on a demo server, and developing a simple module and component for Joomla version 2.5.
This webinar covers:
What is the basic database structure difference between Joomla 1.5 and Joomla 2.5 versions? I was able to create and load modules easily in Joomla 1.5 but I can't do the same in Joomla 2.5? Are too many modules a problem for the Joomla site? Does the extension be compulsory an open source code? Do I really need to switch to Joomla 2.5 from Joomla 1.5 and why? How can I get more information on Joomla extension development? Can I use Jquery framework in the extension development while Joomla uses MooTools JS framework?
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Sit back, relax and let the human brain process something new!
Pre-requisites 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 webinar 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.
◦ Content Management System◦ What is Joomla!?◦ Joomla! Extensions
Module Overview Programming Conventions & Base Structure
Component Overview Programming Conventions & Base Structure
Hands on workshop◦ How to download and install Joomla!?◦ How to install Joomla! Extensions?
Joomla! Module and Component Development – Hands on workshop◦ Joomla! 2.5 Module Development◦ Joomla! 2.5 Component Development - skipped
FAQ’sAndQ&A
OverviewWhat is CMS?Why use CMS?What is Joomla!?Joomla Extensions
Overview Procedural code Vs Object Oriented Code Difficulties with Object Oriented Code Solution to focus on interfaces rather than
implementation◦ Content Management System
Content Management System A content management system (CMS) is a
computer system that allows publishing, editing, and modifying content as well as site maintenance from a central page. It provides a collection of procedures used to manage workflow in a collaborative environment.
Detailed Installation Instructions of Joomla! Is beyond the scope of this webinar due to limited time hence request you to visit http://docs.joomla.org/Use_Joomla!_on_your_own_computer for detailed installation instructions.
Module & ComponentAn overview of both the Joomla! Extensions to understand the basics, conventions and structure.
Overview – Modules What is a module?
◦ Modules are lightweight and flexible extensions used for page rendering. These modules are often “boxes” arranged around a component on a typical page. A well-known example is the login module.
Why should we use a module?◦ Can work standalone◦ Good for code reusability◦ Can work with component for database linking
Conventions◦ Module name should be in small letters◦ Module name should have a prefix “mod_”
Modules Example
Depends on template Added in template using below code:
// no direct accessdefined( '_JEXEC' ) or die( 'Restricted access' ); // Include the syndicate functions only oncerequire_once( dirname(__FILE__).DS.'helper.php' ); //load helper class and function$reviews = modReviewsHelper::getReviews( $params );
//load the layout file from template viewsrequire( JModuleHelper::getLayoutPath( 'mod_reviews' ) );?>
// no direct accessdefined( '_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.
// Include the syndicate functions only oncerequire_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.
//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.
//load the layout file from template viewsrequire( JModuleHelper::getLayoutPath( 'mod_reviews' ) );
This line includes the template to display the output.
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.
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!'; }}?>
helper.php
<html><body bgcolor="#FFFFFF"></body></html>
This file is included to prevent directory browsing. It can be event left blank and whenever someone will access the directory then this file will be default loaded.
Index.html
<?php // no direct accessdefined( '_JEXEC' ) or die( 'Restricted access' );//print user reviewsecho $reviews; ?>
tmpl/default.php
<html><body bgcolor="#FFFFFF"></body></html>
This file is included to prevent directory browsing. It can be event left blank and whenever someone will access the directory then this file will be default loaded.
tmpl/index.html
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
Discover module in Joomla
Go tot extension manager
Click on the discover button to find newly developed extensions
If your programming is correct, it will find your newly developed extension.Select the extension and click on install button to setup the extension.
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.
Display module in front-end
Go to module manager and click on “New” button
Select your newly developed module
Define module position in active template and set other parameters and pages to display the module.I give it position 6 in Beez_20 template.
Module successfully saved, now move to front-end to check this.
You can see user review here
I can’t see the module◦ Check if you have selected correct position in the
active template
Troubleshooting
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!
Module with DB support - Advanced
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
Create table and add fields in the database.Note: Ideally, it is the part of component.
I have done some entries in the DB directly for the demo purpose. It should happen via a back-end component in real environment.
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
Changes in the code
<?php//license details here
// no direct accessdefined( '_JEXEC' ) or die( 'Restricted access' ); // Include the syndicate functions only oncerequire_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 viewsrequire( JModuleHelper::getLayoutPath( 'mod_reviews' ) );?>
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!'; }}?>
helper.php - old
<?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!';
//limit the number of items to load from DB$items = $params->get('items', 10);
//make DB connection $db=& JFactory::getDBO(); $result= null;
//run db query $query = 'SELECT * FROM #__reviews'; $db->setQuery($query, 0, $items); $rows = $db->loadObjectList();
//display and handle error warning if ($db->getErrorNum()) { JError::raiseWarning( 500, $db->stderr(true) ); }
return $rows; }
helper.php – Updated Part 1
For the demonstration purpose, kindly understand and note that Joomla! uses it’s own code conventions to make DB connections and to run a query. It allows in less code and standardized approach.
/** * 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
This component doesn’t exists in the system but we have planned it for future use or next demo of component development.
<?php // no direct accessdefined( '_JEXEC' ) or die( 'Restricted access' );//print user reviews//echo $reviews; foreach($rows as $row){ modReviewsHelper::renderReviews($row, $params);}?>
tmpl/default.php
<?php // no direct accessdefined( '_JEXEC' ) or die( 'Restricted access' ); ?><table width="95%"><tr><td><strong><?php echo ucwords(strtolower($reviews->name)); ?></strong><br /><span style="font-size:9px; margin-top:-5px;"><?php echo ucwords(strtolower($reviews->city));?></span><br /></td></tr><tr><td><?php echo wordwrap($reviews->feedback,130, "<br />\n");?></td></tr></table>
tmpl/reviews.php
Display in front-end
Dynamic records from DB
Please use below link to develop a MVC component for Joomla 2.5 tutorial
Since there is already a detailed component development tutorial hence no need to re-invent the wheel. Also, with the limited available time, I would try to cover it in some session at later time.
FAQ’sCovering frequently asked questions on Joomla!
FAQ’s What is the basic database structure difference
between Joomla! 1.5 and Joomla! 2.5 versions? From the module and component development
point of view, table structure has been updated. Earlier, we had #__modules and #__components
tables which have been merged to #__extensions in the new version.
This new table includes all type of extensions in single table.
I was able to create and load modules easily in Joomla! 1.5 but I can't do the same in Joomla! 2.5?
In Joomla 1.5, system was able to detect a new module automatically but in Joomla 2.5, you would need to discover the module post development.
For this, please go to yoursite/admin and select top-menu/extensions/extension manager and click on the discover tab.
On discover tab, you would be able to find new extensions by clicking the discover button on top-right toolbar.
FAQ’s
Are too many modules a problem for the Joomla! site?
Yes, it there are many modules or extensions then it put extra load on the loading of the page and website.
Some of the websites have been experienced working good with up to 50 extensions but some might start delay in loading.
FAQ’s
Does the extension be compulsory an open source code?
No, but since the CMS is open source and if you want to take benefits of community then it should be an open source code.
FAQ’s
Do I really need to switch to Joomla! 2.5 from Joomla! 1.5 and why?
Yes, there are two types of releases◦ STS: Short Term Support◦ LTS: Long Term Support◦ 1.5 version is LTS version and Joomla! has
officially stopped support for it from April, 2012 so for any further system level issue, it won’t be supported hence it is good to move to next release for code level support. However, forums and community is always available.
FAQ’s
How and where can I get more information on Joomla! extension development?
Please feel free to ask any relevant question regarding this webinar.
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
Next Steps
Questions and Answers Please share a relevant question to this webinar. All questions which are beyond the scope of this
webinar can be discussed separately on my blog at www.vishwashgaur.com or using twitter @vishwashgaur