Front Controller vs. Page Controller
The other day I set out to put together a Front Controller in PHP. The good news: it was stupidly easy to do. The bad news: it didn't feel "PHP-ish" at all. This is probably because a front controller needs a certain amount of supporting baggage, such as some way to configure it. A page controller suffers far less from this problem.
Taking a step back, why would a front controller be used? The pithy answer is that it allows the developer to reuse chunks of code as simply as possible. In Java, there's an architectural impetus to avoid using page controllers, since that generally means putting more logic than necessary into, say, a JSP page. But there's no such pressure in PHP because of the nature of the language.
The "PHP-ish" way of doing things involves putting the common logic in include files, and then referecing them as needed before churing out the page. In order to establish a strong separation of view from controller, it might be adventageous to use something like Smarty for the view, but there's no reason not to use PHP all the way through (indeed, Smarty "compiles down" to PHP)
So, it looks like I was wrong when I said that I might well end up plumping for a front controller. It's a bad fit for the language, and it gets in the way of getting things done. Maybe next time. ;)
Posted in: /tech/php