When to use Front Controller pattern in PHP?

Using the Front Controller pattern in PHP always seemed fairly pointless to me.

I believe that using PHP’s native features with care usually leads to the best code; simple, re-usable components. For example, passing in an object of class ‘MyLogger’ to every object in the system not only ties all the components to using MyLogger, making their use in a system without MyLogger awkward, but the reverse too: any imported code would need to some how be converted to use MyLogger. It’s better to just properly use PHP’s native methods.

The same goes for MVC patterns and so on. Specifically, the front-controller pattern. The paths-to-controller mapping is very effectively done by having one publicly accessible php file for each page, meaning no logic necessary for mapping.

But there was one issue with this that always bugged me. The code in those publicly visible php files, as simple as they may be, (requiring a core bootstrap file and instantiating a couple of objects that do the heavy lifting), were a pain to write automated tests for. Every page would need a test, to check that the cut-and-paste between them had not been broken. Every new page introduced a new weak spot.

But with the Front Controller, all that was reduced to a single page. So there’s the biggest advantage for a front-controller, in my opinion.

Saying that, I don’t think that Front Controller is always the best idea. It can still involve very complex code, or complex debugging. Most who’ve used Apache’s mod_rewrite would agree, I’m sure.

In Martin Fowler’s book, “Patterns of Enterprise Application Architecture”, he points out that it is fine to have a system that uses both Front Controller(s) and Page controllers. There’s a trade-off, and like I’ve heard a thousand times in programming, it ‘depends’. On the requirements, the developers, the technology, and so on. But at least I have now consolidated what to me is the most significant reason for considering the Front Controller, yet why I am unlikely to use it exclusively.


How much will one minute of exercise save the NHS?

Now IMO there’s a good question.

How hard is one minute of exercise? It won’t exactly take you long. About 60 seconds. Go up and down two flights of stairs perhaps.

Now say everyone in the UK did 1 minute more exercise per day than they already do.

I reckon for each minute of exercise that everyone added to their daily routine, the NHS would save in the order of 1 billion pounds every year. I’ve pulled that figure totally off the top of my head, but whether it’s 10 million, 100 million or whatever, doesn’t that make it worth doing?

I don’t vote, because I don’t think one vote can really make a difference. But one minute of exercise might. Maybe I can’t make other people exercise, but I can make a difference to my own health. And if other people read this, who knows, maybe our beloved NHS might stand a chance of surviving. Do we really want to go back to having to pay £15k for a one night stay in hospital? I don’t fancy my chances of staying eligible for affordable healthcare insurance when I reach retirement. I’m only 35, but it’s the one thing that really scares me about the future.

Now we shouldn’t expect everyone to exercise 1 minute more a day – some people cannot. Not just the wheelchair bound; I’m going to stick up for sufferers of mental health problems, to make a point: if one were planing on taking their life, exercise would seem pretty pointless.

But if there is a 10:1 ratio of well to unwell, then just an extra 6 seconds will make up for those who are unable. So, is 66 seconds so much to ask, to look after yourself, the NHS, and the unwell? I think not.

So: Go and do some exercise NOW! Just go up and down those stairs twice. Or 30 pushups, build up those abs and look sexy. Or dig out that awful bush in your garden that you hate. That’s 20 minutes of intense exercise right there! You’ll get a real buzz out of that, I guarantee you. Or do 45 star jumps. Just one minute. For Britain!




Lol @ Andrex

I had a few moments to spare and something on the back of a pack of Andrex rolls caught my eye.

On most household items these days, brands always try to make their product more exciting, easier to use, more attractive to the consumer, and where appropriate, instructions for use.

I always liked a good read of the back of a cereal packet while having breakfast. It doesn’t have to be much; at that time in the morning, even an ingredients list can be more than adequately stimulating. And quite frankly, I’ll also find myself reading just about anything while on the crapper.

But what I found on the back of this Andrex pack was surprisingly surprising:


I mean, really, who on earth needs instructions for wiping their arse? If someone is capable of reading, then they should surely already know how to wipe their arse.

What’s even more surprising, is they seem to have missed out some crucial steps.

So maybe my assumption that everyone is aware of the steps in procedure was incorrect. I mean, if the manufacturers of toilet roll can’t get it right, then perhaps it would be a great public service if someone were to outline a complete procedure – so those looking to become proficient have a definitive reference. After all, mistakes could cause quite a mess.

So I’ve decided to take the liberty of preparing such a guide, which I will include in a future post once complete. It should be noted that while I’m not a professional, I do have a lot of experience.

If anyone has any suggestions on refining my process, please do let me know, so I can work towards a neater, more refined, more accurate, and more useful revision. I will then send it to Andrex – I suspect it will be well received.