As written in my previous post ( http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/ ) I noted that the code for the proper way to write an index file is essentially a Poor Man’s MVC tm.
This method is fine for someone starting out their php journey, it lets them do everything they will probably need to do (they can even add in some apache rewrite rules to make the url look nice). The problem with this approach is that, while it is really fast, it is relying on you to define every single page that you add to your site individually by hand (well, except for the last example). Another problem is that you will inevitably end up with something like this (ok, this might be a bit of an extreme example…):
because the next person to edit the code is too lazy to look at how it actually works. This will repeat itself because the next person after that will figure that is how the code works (ad infinitum).
The alternative is to use an actual MVC pattern, there are lots of tutorials out there to help you reinvent the wheel (which is a great learning tool), or you can start with one that is pre built like CodeIgniter, its cousin Kohana, or one of a pile of others.
It is however, up to you to decide the best way forward for your application, you can use of of the Poor Man’s MVC tm pattern if you really want. If you use it properly, with self control, you will have no problems. It is good to look at other options though, so you can actually understand the advantages and disadvantages of other methods. I find that I like the patterns and organization that are ‘forced’ upon me when I use an MVC framework. It means that I know where the code to control specific actions is, the code for the database/object interactions is over there, and the html (views) is in this spot over here. It makes for easy maintenance, and it makes for faster coding when you know exactly where to go.