Implementing your own Front Controller in Zend Framework
There’s no doubt that the additional complexity of implementing the default Front Controller in ZF results in a number of benefits. The most important ones are flexibility and extensibility. The Front Controller implementation takes into consideration the future growth of your application and its design reduces the level of effort required to extend it. A good example of this is the plugin architecture.
But, what if after evaluating the requirements of your system, you determine that there’s not sufficient complexity to implement the default Front Controller? What if you don’t need all that flexibility, a URL mapper, a ViewRendered plugin or an ActionStack helper. Maybe all you need is just a couple of controllers, and that’s it. It’s clear that the standard Front Controller does provide more options and meets every possible use case requirement, but at the cost of complexity and a lot of classes.
So, what to do? Do you choose a different tool for the job, or replace the default Front Controller with your own implementation? How hard can it be? Is it really that difficult to replace the most important component of the Zend Framework and maintain backwards compatibility?
You are about to find out.
In this series of posts, I’ll try to cover a few things I’ve learned about implementing my own Front Controller in Zend Framework. Most of the ideas and code are based on my previous posts:
- Zend Framework: The Cost of Flexibility is Complexity
- Zend Framework Automatic Dependency Tracking
- Zend Framework Controller: 22% Drop in Responsiveness
- Refactoring the Front Controller of the Zend Framework
- Improving the performance of Zend_Controller
- Zend Framework Architecture
Will simplicity finally meet power?
I think it leans towards the “easy” side, of course depending on how complex functionality you need… tho mostly you prob. can use the builtin functionality and mix and match for your needs.
I get a feeling this series will again showcase how flexible ZF is =)
Jani Hartikainen
April 5, 2009 at 7:09 pm
Hi Jani.
Indeed, ZF is very flexible and allows you to implement your own front controller, router, dispatcher, etc. That’s the beauty of the framework. The Zend_Controller component is very powerful, and it’s not my intention to replace it, but to offer an alternative that decreases the number of decisions a developer needs to make.
ZF is a component-based framework and the components you use are based on your system requirements. My goal is to develop a front controller that is rigid instead of flexible, backwards compatible with ZF applications, focuses on speed, requires 0 configuration and favors convention over configuration. This alternate component may also help lower the barrier to entry for new developers.
Federico
April 5, 2009 at 7:56 pm
[...] are the posts he’s written so far: Implementing your own Front Controller in Zend Framework An Alternative to Zend_Controller: Introduction An Alternative to Zend_Controller: The Router [...]
Making a custom front controller in Zend Framework | CodeUtopia
April 9, 2009 at 7:16 pm