Model View Controller

The Model View Controller pattern is a method of separate your business logic (your Model) from the front end display of the site (your View) through an intermediary (the Controller). The MVC pattern makes it far easier to develop a segmented site, where your View isn't completely dependent on the Model.

In the MVC pattern, this is what a request looks like:

  1. User requests a page from the server
  2. The Controller decides what to do with the request
  3. The Controller sends the request, along with any pertinent values, to the Model
  4. The Model does whatever business processing it needs to do, and then returns any necessary values to the Controller
  5. The Controller performs any additional processing on the return values, and then sends any necessary values to the View
  6. The View renders using the values returned from the Controller

Using an MVC-style setup allows you to completely replace your Model or your View without the need to change either one to suit the other.

There are several MVC Frameworks available for ColdFusion. These include:

MVC explained further...

The Model is your business. Also known as the Domain Model, it includes the logic necessary to interact with your database (create, read, update and delete records) and any logic needed to process data. The model is the objects (the coldfusion components or CFCs) In Java, objects are know as Classes. For more information, see The Model.

The View is what the user sees. Also known as the front end, GUI (Graphical User Interface), or just the user interface. The hope in separating the view from everything else is to allow the developer to swap out or use multiple views on one Model. For example, you could use Flex instead of cfm/html pages for the view.

The Controller acts as the liaison between the view (what the user sees) and the model (what the code does). When a user clicks submit, the controller takes that action or event and sends it to the Model. It also controls what the view does in response to the user's action and/or the model's instructions. Frameworks such as Fusebox, Mach II, and Model-Glue act as the controller layer.

Page Last Updated: 15 Mar 2006, 12:35 PM