MVC

MVC stands for Model-View-Controller and it’s the most popular way to organize and separate the different functions of a web application.

MVC stands for Model-View-Controller and it’s the most popular way to organize and separate the different functions of a web application.

In MVC you have three parts of your app, each of which serves a different function.

First, you have to define what each part of the web app is and how the different parts will work together. The Model defines what data you will have in your app, the relationships between that data, and how you will use it.

For example, if your web app is a blog, the Model says that there are blog posts and users, and defines the relationship between the two (users write blog posts).

Second, the View defines what the app looks like. In the View you define what is on each page and style it up fancy so that people love to visit your website!

Third, you have to connect the Model and the View together. It’s all well and good to let your Model define your data, and your View to determine how that data looks,  but without the Controller never shall the twain meet.

The Controller tells the View about all the parts defined in the Model (blog posts and users), it connects the View and the Model to the database, and ferries information between all three. And every time the user does something (like writing a new blog post) the controller lets everyone know.

The goal of MVC is to separate the app logic, from the app database, and the app look so your app code is nice and tidy and easy to edit. MVC is the organizing principle used by most PHP frameworks, Ruby on Rails, DJango, and many many others.

Cocktail Party Fact

Traditionally, Models, Controllers, and their good friends the databases, made up the backend of a web application. The Views, on the other hand, made up the frontend.

New JavaScript frameworks like Backbone.js are changing all that. What Backbone.js does is let you define a Model-View-Controller for your web app in JavaScript meaning the whole sha-bang can run on the client-side, no server necessary. You can read all about JavaScript MVC frameworks here.

Your email address will not be published.

Cancel

2 comments

  1. Petronila Odell Replied

    “Nice read, I just passed this onto a colleague who was doing some research on that. And he actually bought me lunch since I found it for him smile Thus let me rephrase that: Thanks for lunch!”

  2. furtdsolinopv Replied

    I truly wanted to write down a note so as to say thanks to you for some of the lovely strategies you are posting at this website. My time consuming internet look up has at the end of the day been rewarded with really good details to write about with my company. I ‘d say that we readers are definitely lucky to be in a fabulous website with so many wonderful individuals with good things. I feel very happy to have seen your website and look forward to plenty of more fun moments reading here. Thanks a lot once more for all the details.

Want more articles like this?

Sign up to get the most recent tech news, tips and career advice.