I finally understand Model View Controller (MVC)

Our site (CannedBanners.com) uses the MVC (Model View Controller) system. For the longest time, I had no idea what that actually meant. In fact, I’m not entirely sure I should call it a “system”, perhaps it’s an “architecture” or a “design pattern” or some other term that only adds to the confusion. I’m still not sure. But I think I finally understand what MVC is at least a little bit, thanks to this short an sweet post, Model View Controller Explained. I still have more reading to do, but here’s my explanation of that explanation:

In a web application:

  • The Model is the raw data.
  • The View is how you view the data (or interact with it).
  • The Controller is how the View connects to the Model.

So the View could be HTML/CSS code that presents the data to you on your computer screen. JavaScript and/or PHP (the Controller) might take your interactions with the View and send them to the Model (a database perhaps, like MySQL). Or put another way..

MVC is like Pizza Hut:

  • The Model is the pizza.
  • The Controller is the pizza hut employees.
  • The Views are the dining room, the take out area, the drive thru, and maybe the delivery guy.

People come for the pizza, that’s the real reason they are there (the Model). But that pizza can be delivered and ordered in a number of ways (the Views), it can be delivered to their door, picked up at the take out window, or ordered in the dining room. Working as a go between for the pizza and the ways you can order it, are the people taking your order, and cooking it up.

Simple right?

June 26th, 2011

Comments are closed.