Learning Joomla 1 5 Extension Development

Author:Joseph LeBlanc
Publisher :PACKT Publishing
ISBN :1847191304
Pages : 200 pages

Chapter 1: Joomla! Extension Development: An Overview

Why Extend Joomla!

Any type of program that can be coded in PHP is a potential component waiting to be written.
Your extensions can also be portable. When coded correctly, you will easily be able to install your code on another copy of Joomla! without having to enter the database logins and other basic configuration information again.

Customization versus Extension

Joomla!'s code is designed to be extended rather than hacked or directly modified. Rather than changing the core code, it is preferable to write an extension.


Components are essentially what you see in the "main" portion of the page. Joomla! is designed to load and run exactly one component for each page generated. Consequently, Joomla!'s core content management functionality is itself a component.


Any number of modules can appear on a page. Modules typically make up the elements of a sidebar or content menus. Modules complement the content contained in a component; they are not intended to be the main substance of a page.


When a piece of code is needed throughout the site, it is best implemented as a plug-in (formerly called a Mambot). Plug-ins are commonly used to format the output of a component or module when a page is built.

Creating Toolbars and List Screens

Joomla! has a standard set of toolbar buttons used throughout the back end. These keep a consistent appearance across components, so users quickly become familiar with the corresponding functions.
Like the standard toolbars, Joomla! has a certain look for screens that list a set of records from the database.

Maintaining a Consistent Look and Reducing Repetitive Code Using HTML Functions

Several standard CSS class names are used to format content and HTML elements within your extensions. Additionally, Joomla! includes many functions to automate the generation of checkboxes, dropdowns, select lists, and other common elements.

Accessing the Database and Managing Records

A common database object is used in Joomla! so that only one connection is made during every page request. This object also provides a set of functions to make queries and retrieve results.
Besides a common database object, Joomla! has a standard database table class. Records can be created, read, updated, and deleted using the core functions. Logic can also be added so that child records in other tables are deleted when the parent is removed.

Security and the Preferred Way of Getting Request Variables

Joomla! employs a common method of making sure scripts are only called within the framework and not randomly executed.

Menu Item Control

Navigation is separated from content. However, if a component is not built to take this into account, it is possible that website administrators will lose their template and module selections. To take advantage of the system, it is necessary to use the intended menu item ID number in
generated links.
Also, it is possible to give administrators multiple options for linking to your component.

Controlling the Logic Flow Within a Component

The same file is always called when a certain component is loaded, but different functions are called within. Joomla! uses standard variables to determine which function to execute on each request. There are also classes available to automate the flow based on these variables.

Configuration Through XML Parameters

Rather than creating a separate table to hold the configuration for an extension, Joomla! sets aside a place where short values can be held. These variables are defined through an XML file, which is installed with the extension.

Packaging and Distributing

Once all of the code is complete, it is easily packaged for others to use. A listing of all the files involved is added to the XML file. Any queries needed for table creation are also included. All the files are then compressed in an archive. The extension is then ready to be installed on any Joomla!-based website.

Chapter 2: Getting Started with Component Development

Joomla!'s Component Structure

Joomla! employs a specific naming scheme, which is used by all components.
The code is split into two folders, each bearing the component name prefixed by com_. The component in this book will be called reviews.
Therefore, you will have to create two folders named com_reviews:

  • components/com_reviews for the front end.
  • administrator/com_reviews for the back end.

When the component is loaded from the front end, Joomla! will look for a file with the component's unique name ending in a .php extension. Within the
components/com_reviews folder, create the reviews.php file.
Add the file admin.reviews.php in administrator/components/com_reviews

Executing the Component

you can load the component's front end by opening http://localhost/joomla/index.php?option=com_reviews
To make this component slightly more useful, open reviews.php and add the following code, then refresh the browser:

defined( '_JEXEC' ) or die( 'Restricted access' );
echo '<div class="componentheading">Restaurant Reviews</div>';

Function defined() was called at the beginning of the file. This is a check to ensure that the code is called through Joomla! instead of being accessed directly at components/com_reviews/reviews.php. Joomla! automatically configures the environment with some security safeguards that can be defeated if someone is able to directly execute the code for your component.

For the back end, drop this code into administrator/components/com_reviews/admin.reviews.php:

defined( '_JEXEC' ) or die( 'Restricted access' );
echo 'Restaurant Reviews';

Joomla!'s Division between Front End and Back End

For all Joomla! components, code empowering the back-end portion is kept away from the front-end code. In some instances, such as the database table class, the back end will use certain files from the front end, but otherwise the two are separate.

Registering Your Component in the Database

Navigation can be provided if you register the component in the database by adding a row to the components table. We will perform this registration using the following query.

INSERT INTO jos_components (name, link, admin_menu_link,
admin_menu_alt, 'option', admin_menu_img, params)
VALUES ('Restaurant Reviews', 'option=com_reviews',
'option=com_reviews', 'Manage Reviews', 'com_reviews',
'js/ThemeOffice/component.png', '');

Adding this record gives the system some basic information about your component. Now that the component is registered, you can also create a link for the front end.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.