I’ve been researching PHP frameworks as of late for some personal projects, and it looks like most of them use a front controller to mimic a response. The controller gets the params from the request, and re-routes by sending the appropriate headers depending on the logic. This is the ‘response’. Is this the best way to do this in PHP, or are there other theories about how to handle re-routing and responses?
I’ve been researching PHP frameworks as of late for some personal projects, and it
Share
a front controller lends itself quite well to a web environment, allowing you to funnel all requests to your application. since HTTP is stateless, and a user can, in a sense, inadvertently stumble upon parts of your app by accident (ie, hitting random URL’s), a front controller allows you to determine the entry point of your application, and respond appropriately.
edit: in response to the comments, i think the confusion may be that java has a lot more structure to it than PHP, which might be overcomplicating the whole thing? ultimately PHP can provide for the very basic interaction from request to response:
and from there you can layer in all sorts of things to front controllers passing request objects down a filter chain to a page controller which reroutes to the appropriate model which grabs data via your db abstraction layer, filters it, back up to the controller, and on to the view which constructs the appropriate response, all the while firing off random event hooks. ultimately it’s up to you (as developer) to choose what level of complexity/separation you’re looking for. this is both the beauty and evilness of PHP 🙂