Joomla! Applications: The Basics
As I posted in a previous blog, the Gentle Beginnings site that I left over a half a year ago was 90% done, but was missing one core feature – the ability to post and read birthing stories. Recently I revisited this site to add the birthing story component, and learned a couple of hard lessons about Joomla! application development. Hopefully by posting this I can shed some light on the less documented portions of Joomla!, and perhaps save someone else precious time.
Joomla! components are distributed as a zip file and consist of two parts – the front-end interface (what the site visitor will see), and the back-end interface (how your site administrator will use your component). There is a components folder and an administrator/components folder to hold these two divisions. An XML file must be present in your zip archive to explain your component’s directory structure to the Joomla! extension installer. A line-by-line explanation of this XML file is beyond the scope of this blog.
Joomla! gives the user much leverage when it comes to developing both back and front-end interfaces, but both share one quality – they must use a consistent naming convention for the application controller to access the file correctly. In other words, you name your component com_birthingstory, and your file birthingstory.php. You can control your logic in one file, which is what I tried doing at first, but be warned that this is extremely limiting.
Joomla! builds its out-of-the-box components using an MVC architecture*, where the model file (in our case, birthingstory.php) will instantiate a controller instance and pass the controller a ‘task’ variable. The controller then uses the task variable to process some information and present a view. If no task variable is set, a default action is processed, and a default view is set.
In my first run of com_birthingstory, I did not use multiple views, and therefore I could not set multiple menu types! This was essential for com_birthingstory, as one of the requirements was that only registered users could post stories, but anyone could read stories. So two views were created, called EnterStory and DisplayStories. Again, naming conventions for these views must be consistent with directory structure. If your component is com_birthingstory, and your view is in view/enterstory.php, the class must be named BirthingStoryViewEnterStory.
Once these views were created, my next task was to process data in the controller. This can be done using pure PHP, or even external classes/libraries if you choose – but Joomla! is an application development framework as well as a solid CMS. So why reinvent the wheel? Here are some classes I used, with a brief description:
- JModel – Provides a common interface for your model to inherit. Holds core application configuration data that can be used in your methods.
- JController – Provides methods to handle requests (the task variable I mentioned above) and set a view for the end user. Includes redirects with messages indicating success or failure.
- JRequest – An essential component of even procedural Joomla! development, the JRequest class contains methods to cast variables, sanitize input, and even recursively strip slashes. You can specify the variable source ($_GET, $_POST, $_FILE, etc.) You really have no reason to not use this class.
- JFile – A file handling class, contains methods to move/copy files, make file names safe, check extensions, and more. This class surprisingly lacks the ability to check through Mime Types, which is a basic part of file security. Therefore if you use this extension you’ll likely have to include some raw PHP as well.
These classes will help get you started, and more are available to browse at http://api.joomla.org/. Remember some tips though, as they may keep you from the instant refactoring I had to endure (taking up an entire weekend…)
- Use MVC where necessary. If you don’t need multiple menu options for a component, you may not need it. (com_birthingstory does not use MVC for the administrative side)
- Use the built-in classes of Joomla! to develop. They are bug-tested and will definitely help reduce your overall development time.
Any questions/comments/additions? Other useful Joomla! classes? Post them here.


ShareThis