In my previous job, I used an MVC approach to design our web applications. But I noticed that there was a lot of redundancy in the "main" scripts. Basically, I did the following:
- Define the used variables
- Access session data
- Call the appropriate method based on the current action
- Process the results
The only necessary part for each script is step 3. Call the appropriate method based on the current action. So what am I doing with a bunch of nearly identical scripts that have to be customized?
This is where the Front Controller pattern comes in.
The Front Controller Pattern
In a nutshell, a Front Controller is a single script that serves as a front-end for all your applications. All the other scripts are called through some parameter (usually defined in the URL as a query string variable, or some path to a "script").
The trick is that the front controller already handles authentication, session, etc. If you want to add, for example, a traffic control routine to limit the number of calls per second, you can do it in the front controller.
For more information about the Front Controller pattern, check out these links: