jump to navigation

Zend Framework: The Front Controller May 19, 2011

Posted by Tournas Dimitrios in Zend Framework v1.10.

The Front Controller is the “hard – worker ” of an MVC application , it was  designed to be lightweight, modular, and extensible . The Controller  receives a request (usually a HTTP request ) and it response by returning the requested data ( if available)  . Although the concept is simple , there is quite a bit going behind the scenes . This article will just outline the basic functionality of the Front Controller .

The Front Controller is not a monolithic block but is composed from many components , connected with each other like a chain . Of course the representation of a chain in OOP implementation is expressed by Classes . Each Class can be extended or even replaced by a custom Class , so that the functionality of the Front Controller can highly customised . By default the Front Controller is targeted to web applications ( web browsers ) , so we will “stick” with this functionality . Advanced users can transform the Front Controller to other services like : CLI , web- services (SOAP , REST ) , by extending or replacing each part ( Class )  .

The Front Controller beyond the task  of  instantiating and orchestrating it’s  components , it dispatches events . These events can be captured by the other MVC components and they will behave accordingly . Each event has a unique name , so we can capture that specific event and implement functionality at specific timing of the Front Controller’s work-flow . See this graphical representation of the application work-flow and this practical example .

The default components ( Classes ) used by the Front Controller are :

The basic steps of the Front Controller functionality in the exact order :

  • The Front Controller is instantiated and requested data is passed to it
  • A request object is created
  • Front Controller dispatches  a ” Route Startup ” event
  • The Router object reads information from the request object
  • Front Controller dispatches a ” Route Shutdown” event
  • Front Controller dispatches a ” DispatchLoopStartup” event
  • The Dispatch loop is started
  • Front Controller dispatches a ” PreDispatch” event
  • The Dispatcher object calls the Action Controller
  • The Action Controller writes data to the Response Object
  • Front Controller dispatches a ” PostDispatch” event
  • Is there other actions left to call -> repead the last 3 steps , else go to next step
  • Front Controller dispatches a ” DispatchLoopShutdown ” event
  • Front Controller send response back to the browser


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s