Thursday, July 9, 2009

Joomla component in Zend Framework example

Joomla is a nice CMS(content management system) and Zend Framework is once of the famous and widely adopted MVC Framework since its first release. One of the nice thing about Zend is its loosely coupled components.

Keep in mind that component in joomla and Zend Framework don’t refer to the same concept. Those who have worked in Joomla and Zend Framework know the difference.

In this article I’m not going to discuss what Zend and Joomla are all about and how component is different in both, but instead I’m going to share a little secret of how to develop joomla component in Zend Framework.

This article is not for those who are unaware of joomla and Zend.

Although joomla has own API for developing its components and modules, but you can use any php code in addition to its own API.

Reason is simple. Joomla is developed in php.

As Zend also used php behind the scene, so both can interact easily.

This was a bit of introduction.

While discussing all these things I assumed that you have little knowledge of joomla and have some knowledge of Zend Framework as well.

So let’s dig in.

Before writing any code you will need to successfully download and install joomla. Also download Zend and save it in the directory of your choice.

Once successfully installed joomla, open joomla/administrator/components and create a folder called com_yourcomp.

This is your component folder. You will need to create a file named yourcomp.php

If you want to add component in your administrator, the name should be admin.yourcomp.php.

That’s it, you have now created a the necessary directory structure for your joomla component development.

If you write a line “Hello world!” in youcomp.php or admin.yourcomp.php and browse your page as


you will see

“Hello world” printed.

These are the minimum requirements for developing joomla component.

Now we will using Zend Framework classes to add code to this file plus we will create Zend directory structure in order to work with Zend MVC.

Create following directory structure in your joomla/administrator/components.

Here you can see that my component name is com_advertisers.

In this directory I’ve

* admin.advertiser.php file
* application directory
* Joomla directory

The file admin.advertiser.php will serve as the bootstrap file.

Application directory contain specific directory for controllers, models and views.

The most important role is played by our Joomla directory in developing joomla component in Zend Framework.

This directory contain Controllers/Plugins/Router.php file.

This file contains code for calling specific action based on particular task. Before going to discuss code in the Router.php file, I’m going to show the code need in our admin.advertisers.php file.
define('ROOT_DIR', dirname(__FILE__));
. PATH_SEPARATOR . ROOT_DIR . '/application'
. PATH_SEPARATOR . ROOT_DIR . '/application/models'
. PATH_SEPARATOR . get_include_path()

require_once "Zend/Controller/Front.php";
require_once "Joomla/Controllers/Plugins/Router.php";

$frontController = Zend_Controller_Front::getInstance();

$frontController->registerPlugin(new Joomla_Controllers_Plugins_Router());


In the first few lines I have included path to our com_advertisers directory, application directory and models directory.

Next I include Zend Front Controller files and Router.php file. I’ll discuss code in the Router.php file later as it contain the most important code.

Next I initialize front controller, register Router Plugin class which is defined in our Router.php file, set controller directory and call dispatch.

That’s it. We have now defined our bootstrap file.

One important thing is setting path to our library files that contain Zend component.

You can include path using set_include_path or set it in your php.ini file.

If you don’t include this path, your application will not work as you expected.

Now go to controllers directory and create IndexController.php and write the following code in it.

class IndexController extends Zend_Controller_Action
public function indexAction()
public function editAction()
public function saveAction()

Noting special here. I’ve created only three actions.

Go to your application/views/scripts directory and create directory called index and create three files index.phtml, edit.phtml and save.phtml.

The code above is what you will need to work with Zend Framework MVC. In order to integrate this code with joomla will need one additional files. In my case the file is Router.php

I have create this file in com_advertiser/Joomla/Controllers/Plugins/ directory.

The code contain in this file is

class Joomla_Controllers_Plugins_Router extends Zend_Controller_Plugin_Abstract
public function preDispatch(Zend_Controller_Request_Abstract $request)
$task = $request->getParam('task')
switch($task) {
case 'edit':
case 'save':

First I’ve include plugin class and then extended my Router class from Zend_Controller_Plugin_Abstract.

This Zend_Controller_Plugin_Abstract class contain a method preDispatch that is called before any controller is called in the routing process.

In the preDispatch method, I get the param “task” and write a switch statement to check this param. If it is edit, I give control to my editAction of the default IndexController. And similarly if it is save, I route request to my saveAction and by default, if no parameter is specified, the request will be dispatched to indexAction of my IndexController.

That’s it.

Now if you write


It will show what ever you have written in your save.phtml file.

And similarly if you write


it will route you to editAction and will display whatever you have define there.

Any question and suggestion are welcomed.


  1. FAHEEM -> thks alot for this tutorial!!!
    I will prove!!
    Suggestion: you have the base, could you make a plugin? could be great!! ;D

  2. Hi,

    Intresting tutorial.

    I encounter the folowing problem intregrating different controllers with joomla,

    I got the folowing message:

    Class 'JModuleHelper' not found in www\joomla\administrator\templates\khepri\index.php on line 41


  3. Is there Any Sample Joomla Module which is build on Zend Framework


  4. Great tutorial. I hesitate to use ZF for the MVC since Joomla already has a lot of overhead in it's MVC. An empty component does around 4MB per request. Adding ZF on top of that, I don't know. But great tut none the less.

  5. Hi,
    Very goog tutorial.

    The problem with the JmoduleHelper is linked with the Zend Autoloader.

    Youm ust include the class that you need to use and not instanciate the Autoloader.

    That's all.

  6. Great Job
    If you have a second controller or a modular ZF application, how do you manage its routing from joomla URL to ZF internal URI?

    1. My suggestion would be to extent the functionality of the Joomla_Controllers_Plugins_Router class.

      To illustrate how this can be achieved I'll take the following URL:


      and then in the router plug in you have something like:


      // If module, controller, task/action are set assign them to the request
      isset ($params['module']) ? $request->setModuleName($params['module']) : null;
      isset ($params['controller']) ? $request->setControllerName($params['controller']) : null;
      isset ($params['action']) ? $request->setActionName($params['action']) : null;


      You have two preconditions with this approach.
      1. You have set modular architecture in your front controller
      2. You have set default values for: module, controller, action because as you can see those values are set in the request only if the exist as variables in the request (params).

      Hope it helps

  7. Good post about joomla. I think mostly website is using that joomla. because it can handle easy accept so as. Joomla Developers

  8. Best Software Downloads and Reviews. the most comprehensive source for free-to-
    trysoftware downloads on the WebBEST 4

  9. nice tutorial thnks

  10. I wanted to stop by and let you know, I read this article a while ago and loved the idea. So I have taken the basics and run with them. Basically, I am creating a component to run the Zend apps in the system. I would love your input on my project and any thoughts you may have:

  11. I wanted to know if i can install joomla and zend optimizer on a local machine and check as to how the performance has improved on the same desktop.


  12. It was just amazing information sharing and it's helpful for everyone.
    - Prom Dresses

  13. I thought I know everything (or almost) about Joomla. I was soo-o-o wrong! Thanks for wonderful tutorial!

  14. Thanks this was inspirational. I did things a little bit differently, but seeing that others had brought Zend into Joomla successfully encouraged me to do so. I was able to build my component much faster using Zend capabilities. I was also inspired by the anonymous guy who took it and ran with it and created
    I didn't see that comment until after I started my own thing so my approach was a little different, but I used that project to solve a few problems with what I had done. In the future I plan to start with that project as a base.

  15. Nice framework explanation.It really excellent and great information.i am glad to write this comments.It is also very impressive.Thanks for making it.

  16. Such a nice and unique information sharing. thanks for that.
    - Dividend tax

  17. Such a useful information sharing and its helpful for everyone.

    - Tend Skin Products

  18. really amazing blog and I was thankful to you for sharing such a useful information.
    - CRM Services

  19. it was just informative news and thanks for sharing such a useful information.
    - anna maria island rentals

  20. We offer high end Site Design and SEO services in New York. We explore new horizons regularly to get you the edge over competitors.

    - website companies

  21. Great…Its Working…Really Good… its very useful for topic.Keep writing some more interesting topics like a Joomla Developer

  22. Very interesting read. I have a lot of work and learning to do. Thanks!
    Joomla Developer

  23. Great information! Thank you for sharing your ideas. I like your post and share it on my twitter and Facebook wall Joomla Developer .

  24. A great article explaining about website development very clearly. I have no idea how many people will read your post, because I already send your post to my friend list on twitter, facebook and stumble upon.

  25. Non-Profit Logo Design
    Accurate results and precision is the base you select the developers to redesign your portal. You have won our satisfaction level and further we will surely work with you.

  26. Thanks for sharing such useful information. It will helpful for those people what they really need.

  27. Update yourself with the latest news on the trading world. If you scrutinize the daily news about equity market, you surely will come to know how various online sharks (platforms) are duping the investor in the shape of money lenders.

  28. really amazing blog and I was thankful to you for sharing such a useful information.
    - CRM for Iphone

  29. Hey, Absolutely abundant work, I would like to accompany your blog anyhow so amuse abide administration with us,

    Advertising agencies in pakistan

  30. Finally a real comment: I just used this for a project of mine which had to be integrated with Joomla after the fact. All of my routing and such was dependent on the standard Zend route, but that doesn't work in Joomla. I took Rob Allen's query router and updated it a bit to include some Joomla things like the option: Modifications are at like 91-95 to account for the option and ajax raw format controller

  31. Are you looking for an expert, experienced and equally dedicated Joomla Developer for your new project or for the maintenance of your current project? Our Joomla Web Developer’s team of skilled professionals develops or modify modest to complex Joomla Web Application Development. Our specialized Joomla web developer delivers cost-effective solutions with accuracy and timeline in classify to develop Joomla based website for superior efficiency and usability of CMS.

  32. The best design of website could making in only joomla tutorials.Because i designed one website in joomla tutorials.It was very nice compared to other tutorials websites Web Design Services Bangalore | Web Designing Company Bangalore

  33. Great Work. This post is worth everyone’s attention. web design company in chennai

  34. Informative article, just what I was looking for.seo services chennai

  35. Can truly relate and retain this outstanding post. Very well written. web design company Chennai

  36. This article shares great information, thanks for sharing it with us...
    Yasir Jamal

  37. Really nice thing. And actually this will be included with whatever they have to involve in particular actions and all. Nice and also i am expecting much more posts from you. Ecommerce Website Design Company In Dubai-UAE

  38. Nice blog. Thanks for sharing such great information.Inwizards Inc is a Joomla web Development company offers quality joomla development services best in web industries. Intrested click here - Hire Joomla Developers, Joomla Development Services

  39. Hey buddy I just desired to let you know that I really like this piece of writing, keep up the superb work!
    "seo services dubai"

  40. Thanks ! for sharing this wonderful news with us.I really like your post as it is informative as well as interesting.
    "seo dubai"

  41. Thank you for sharing such a great information with us about Joomla.