Categories

Playing with MVC

I’ve been playing around with some PHP MVC frameworks lately, Cake PHP primarily, with Symfony and Ruby on Rails for comparison. Its my first foray into the MVC design method at all, and while I’m seeing the benefits, at times it seems to be an almost frustratingly efficient system. I say that in the sense that because everything can be broken down into such basic elements, it begs the question of just how basic you should be with certain things.

For example, I have my Posts table setup with a boolean field “is_page”, indicating whether the post should be displayed as a post or a page, this information is also used to determine whether the page title should be displayed as a menu link. When taking the MVC approach, Posts and Pages should be seperate, and while that would be correct, it would also require creating 2 controllers, with essentially the same functions and code in each. That seems a little redundant, as the only real difference should be in the layout used when the item is displayed.

Nonetheless, as the pieces slowly come together, I’m beginning to understand the power of a solid MVC framework. If you find yourself creating websites that share common elements, such as contact forms or a coupon system, you’ll find great benefit from setting aside some time to really play with a few frameworks and see which one is what you need.

It must also be said that there are a ton of choices in PHP frameworks out there, many of them are quite solid. The alternative to CakePHP that I’ve been looking at most lately is the Zend Framework. It offers a lot of the handy abilities of CakePHP but is much more flexible, lightweight, and very modular.

Comments are closed.