MVC: A Beginner’s Guide

 

Introduction

So you want to learn about MVC? This article will hopefully clear some of your possible confusion when it comes to this three letter acronym that can strike fear into the hearts of many. Like most topics in web development, it’s always a little confusing when you first take a look at it, but after you read up on the topic, and try it for the first time, it’s as easy as pie! Read on, my friend!

What the heck does it stand for?

MVC stands for Model-View-Controller. It is an architectural pattern used when engineering software. Basically, it separates the three main parts of an application and makes them independent of each other, therefore they can be designed, tested, and worked on independently of each other.

In the world of web development, MVC is usually used with a framework such as CakePHP or CodeIgniter. For the purposes of this post, we won’t be focusing on any individual framework, more on the idea of what MVC really is and how it can be used. If you would like to delve into one framework as a beginner, though, I highly recommend CodeIgniter to get started. It is simple, yet powerful, and won’t confuse you when you’re getting started.

M

Models are very simple. They are the knowledge of your program, they represent it as either a single object, or a structure of multiple objects.

In the static web world, your model could be simply the HTML of your page. It is the skeleton of your content, how it will be structured, and of course, the content itself.

V

The view is a visual representation of a model. In a program, a view fetches the model’s data, and displays it. It can also update the model by collecting data.

A static example of this is plain old CSS. The CSS adds visual style to your model (the HTML), it is used as the “skin” to the skeleton of your content. We can switch from one style to another and not affect the model at all.

C

The controller is what puts it all together between the user and the system. It receives user’s input in the form of commands and data, then outputs the views that are to be presented.

An example of the Controller would be the browser. It takes the HTML, CSS and any other jargon and outputs a readable web page for the user to interact with. It can also accept user input in a sign up form for example.

Conclusion

Hopefully I haven’t confused you too badly, and you have at least a basic understanding of MVC now. It’s literally all around you, as I have shown in a simple HTML/CSS/Browser example. If you want to read more, the CodeIgniter documentation explains it in terms of their own framework. Take a look at those docs here. Thanks for reading!

Be Sociable, Share!

Related posts:

  1. Review of “PHP for Absolute Beginners”


Written by Dixon Crews

Hey, I'm a high school student who really loves web design and development from North Carolina. I'd love to go to school to learn even more about design, possibly computer science, and eventually having a job designing and developing websites! Twitter | Website

 

5 Responses to “MVC: A Beginner’s Guide”

  1. Karl Roos Says:

    December 29th, 2009 at 2:01 pm

    A model in MVC should never contain HTML code. Markup is also a part of the view. The model is where you put your logic, your database queries etc.

    Well written for a 15 year old thought, keep it up ;)

  2. monad Says:

    December 30th, 2009 at 12:47 pm

    I think the “HTML-CSS-browser == MVC” formulation is sort of wrongheaded, although to some extent, I suppose, it comes down to what the meaning of ‘is’ is.

    There was a fairly epic throwdown at Coding Horror a while back which explored both side of this issue pretty thoroughly, and is well worth the read.

    http://www.codinghorror.com/blog/archives/001112.html

  3. Dixon Crews Says:

    January 1st, 2010 at 5:34 pm

    @Karl:
    Yes, I know that a model should never contain HTML. I’m simply providing an example of what a model is, in essence.

  4. Muhammad Adnan Says:

    January 6th, 2010 at 12:25 pm

    I like MVC , It is more manageable framework ;)

  5. Rashi Says:

    July 16th, 2010 at 6:24 am

    I will not say that i was aware of MVC because before reading your post it was just a name of a tool for me but now i got what it is. Thanks For sharing this for us.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
connect with me!