Book Image

Learning Joomla! 1.5 Extension Development

Book Image

Learning Joomla! 1.5 Extension Development

Overview of this book

Table of Contents (17 chapters)
Learning Joomla! 1.5 Extension Development
Credits
About the Author
About the Reviewer
Preface

Topic overview


This book will cover the following topics regarding the development of extensions for Joomla!:

  • Creating toolbars and list screens

  • Maintaining a consistent look, and reducing repetitive code by using HTML functions

  • Accessing the database and managing records

  • Security, and the preferred way of getting request variables

  • Menu item control

  • Controlling the logic flow within a component

  • Configuration through XML parameters

  • Packaging and distributing

Let's take an overview of these topics.

Creating toolbars and list screens

Joomla! has a standard set of toolbar buttons that are used throughout the backend. These provide a consistent appearance across components so that users quickly become familiar with the corresponding functions. When necessary, the labeling and functions of these buttons can be changed, and new buttons can also be added.

As with the standard toolbars, Joomla! has a certain look for screens that list a set of records from the database. These lists usually have links to the edit screens for the individual records and have toggles that change the publishing status of the record. Automatic pagination is also available for lists.

Maintaining a consistent look, and reducing repetitive code by using HTML functions

Several standard CSS class names are used to format content and HTML elements within your extensions. This makes it easy for your extensions to seamlessly blend in with the rest of the website. 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. These functions are database-independent and are designed in such a way that you can install multiple copies of Joomla! into the same database when desired.

In addition to having 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

Because Joomla! is a web application deployed within public reach, it is necessary to protect it against security vulnerabilities. Joomla! employs a common method to make sure that scripts are called only within the framework, and not randomly executed.

Besides unintended script behavior, maliciously-submitted data can be used by hackers to gain access to your database. Joomla! provides functionality that prevents attacks of this kind.

Menu item control

A noteworthy feature of Joomla! is that 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 templates and module selections. To take advantage of the system, it is necessary to refer to the intended menu item in generated links.

Also, it is possible to give administrators multiple options for linking to your component. This will allow the selection of different display options for the frontend without the need to construct long, confusing URLs manually. These options can additionally offer administrators some simple configuration controls.

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 it. Joomla! uses standard variables to determine which function to execute on each request. There are also classes available to automate the logic flow based on these variables.

At a minimum, components are designed to separate the output from the database and other processing functions. Larger components will separate the logic flow using a controller, the data access methods using a model, and the output using views. These conventions make it easier to maintain the code and help the component perform in a reliable and predictable way.

The elements of larger components come together to form what is called the Model View Controller (MVC) design pattern. Rather than being a specific piece of code that you include, MVC is a method to organize your project. The use of MVC helps you keep HTML markup, database queries, and user requests separate from one another so that code changes cause minimal disruption. Other software projects such as Ruby on Rails, CodeIgniter, Django, CakePHP, Zend Framework, and Qcodo also use MVC as a way of designing web applications.

When writing MVC code the first time, it may seem like unnecessary work up front. However, as your components grow, MVC makes your code easier to read and maintain. For instance, when an extra<div> tag must be added around your output, another programmer maintaining the component will automatically know to look amongst the views instead of deciphering the controller function that accepts uploaded files. Code that mixes processing and HTML output quickly becomes difficult to maintain; if() statements pile up and you never know if you are adding tags to the right place. Although the use of MVC in Joomla! components is optional, it is strongly recommended for nontrivial code.

Configuration through XML parameters

Rather than create a separate table to hold all of 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. The XML file also provides default values and constraints for these parameters. The saving and retrieval of these values is automated-that is, handwritten queries are not needed.

Packaging and distributing

Once the coding is complete, it can be 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 of the files are then compressed in an archive. The extension is then ready to be installed on any Joomla! based website.