A Mixx of MVC

posted on January 11, 2009

As I talked about in a previous article, understanding model-view-controller is important to programming with the CakePHP framework. Here is an example of how MVC could be used on Mixx.

Disclaimer: I don’t know if Mixx uses MVC. It probably doesn’t, but this is an example of how it would use MVC.

Model

The model that we will be using is a post. All of the data about this post is in the database. Although this example will utilize other models, such as the user model, the main model is the post model. You can think of a model as being a row in the database. The table for this model is called posts, and the model is a row under the table.

View

This story can represent the view portion of an MVC architecture.

This story can represent the view portion of an MVC architecture.

We will be using a small portion of Mixx as the view of this example. Although the view consists of everything on the page, it is easier to break the view down to just a small portion. The view includes everything here. The data is supplied to the view by the controller. The controller gets this data from the model. Everything here, including the vote for button and vote against button, is part of the view. Different actions taken from the user interface, another name for the view, will cause the controller to do different functions.

Controller

The controller is the key to MVC. It connects the model and the view by supplying data found in the model to the view. The view then displays this data to the user.

The controller also handles actions from the user. As seen in the photo above, when the user clicks on the vote for or vote against button, although these buttons are part of the view, the controller takes action. The controller will make all of the necessary calculations, such as the new number of votes and votes per hour, and then alert the model to update it’s data.

All parts of MVC are necessary for a working application. Without the model, there will be no data, and nothing for the application to do. Without the controller, nothing can happen. The controller handles all of the actions by the user. Without the view, the user will not be shown anything, and will not be able to take any action.

Still don’t understand model-view-controller? It’s a difficult concept for some – leave a comment and I will be happy to help you out.

Tags: , , ,

Like this post? Someone else might, too.

  • RSS
  • Reddit
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Technorati
  • Twitter
  • Digg

Leave a Reply

Subscribe to gulati.info

Subscribe via RSS (?) Subscribe to our RSS feed Subscribe via Email
Follow me on Twitter Follow me on Twitter