The Dopefly Tech Blog

« The Dopefly Tech Blog Main page

Easiest Ever MVC with ColdFusion

posted under category: ColdFusion on February 17, 2010 at 1:00 am by Nathan

Slowing down and backing up, this is a very quick introduction to making an MVC application in ColdFusion.

First, make yourself an appropriate directory structure. Follow along here, it's really simple.

There are a hundred a thousand infinite different ways to go from here. Let's try the most basic way I can think of. Your browser should always hit the controller no matter what, so let's put in an index.cfm to redirect /app/ visitors to a default controller, /app/controller/main.cfm.


<cflocation url="controller/main.cfm" />

Now that main.cfm controller file: /app/controller/main.cfm
<cfinclude template="../model/main.cfm" />
<cfinclude template="../view/main.cfm" />

And the model: /app/model/main.cfm
<cfset name = "Nathan" />

Finally, the view: /app/view/main.cfm
<cfoutput>Hello, #name#!</cfoutput>

That is about as simple as an MVC application can be, and from there, you can begin to enjoy the advantages of MVC.

You can download this very simple MVC app.