Archives For Understanding MVC

A quick series on the MVC (Model, View, Controller) design pattern commonly used by frameworks.

This entry is part 1 of 3 in the series Understanding MVC

I’m planning on writing several posts on the Yii framework (for PHP 5), which I’ve been using for the past several months. Before getting into that, though, I thought it’d be worth while to write about the MVC—Model-View-Controller—architecture first. MVC (first defined 30 years ago!) has become a standard approach for frameworks and many other types of application development, where the emphasis is on separating presentation from logic. By taking this route, you can more easily tweak individual parts without (hopefully) breaking the whole.

The basic concept is relatively simple to understand, but I found that the actual implementation of the pattern can be tricky. In other words, it can take some time to master where you put your actual code. In this post, I write about the individual pieces and how the relate to each other. In a follow-up post, I’ll write about how to communicate between them, and what in the world $this means at any particular point! Continue Reading…

This entry is part 2 of 3 in the series Understanding MVC

[intlink id=”453″ type=”post”]In a previous post[/intlink], I introduce the MVC design pattern, commonly used in frameworks and other programming situations. In that post, I wrote about the Model, View, and Controller parts: their specific roles and how they relate to one another. Those are the fundamental pieces of MVC, but I personally found that knowing what this means in terms of code is a whole different subject. I want to eventually focus on that, but first I have to discuss some of the conventions that frameworks use and how they might differ from one framework to the next.

In this post, I’ll use a hypothetical employees-departments example, giving examples using the Yii framework, the Zend Framework, and Ruby on Rails (these are the three frameworks with which I’m most familiar). If you’re using a different framework, let alone a different language, some of the syntax and particulars will change but the basic principles will still apply, and that’s the important thing I’m trying to get across here. In my next post on this subject, I’ll provide some representative code (I was hoping to do that here, but this subject became too expansive, as commonly happens for me).

Continue Reading…

Understanding MVC: Coding

October 15, 2009
This entry is part 3 of 3 in the series Understanding MVC

In the [intlink id=”453″ type=”post”]first part[/intlink] on this series about the MVC (Model-View-Controller) design pattern, I discuss the individual parts and what they represent. In the [intlink id=”505″ type=”post”]second part[/intlink], I layout some common conventions of MVC frameworks. Both of those posts lead up to this one, in which I want to talk about actual code. In my opinion, it’s not too hard to understand what MVC means, in theory, or to follow a framework’s naming rules, but then you start developing a project and can quickly become confused as to where you actually put your code.

Continue Reading…