So I’m trying to figure out the easiest approach to create a simple Model-View-Controller implementation in PHP. I found a sample implementation, but there are a number of things I don’t like about it, starting with the fact that the Web stuff is all embedded in code, which violates one of the key tenets of the pattern.

However, there are some things I like about it. Rather than taking an approach like Struts and using a common controller for everything, I’d prefer to write my own, simple controllers in this case. That rules out a framework like Phrame, which is patterned after Struts. (php.MVC is another PHP port of Struts.)

Looking back at the example that I pointed to in the first place, I think that further simplification of it may yield the best results. Rather than creating a separate Controller file, I’ll put my controller logic in the root index.php file. Then I can build a model like the one in the example, and rather than creating a view class and retrieving the markup as strings, I’ll just include the appropriate PHP files to provide the view.

Taking things a step in a Rails-esque direction would mean building some scripts that generate these components for you based on the structure of your database. Since this is a one-off, I’m going to focus on making it work properly and deal with making it generic a bit later.

Given that I’ve been building Web applications with MVC frameworks in Java for years, I’m surprised at how difficult it has been to find away to apply this pattern to my PHP work.