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 MrNate

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.

Too old to comment!
On Feb 18, 2010 at 1:00 AM Patrick (spenceley, who eats said:
On speed alone that will probably run faster than cold box.

With a cleaner stack trace 2 boot. ;)

On Feb 18, 2010 at 1:00 AM Billy Cravens (bdcravens at the ever popular said:
Congratulations, you've just invented Fusebox 2 :-)

On Feb 18, 2010 at 1:00 AM Nathan Strutz ( said:
Cute, but it's not really fusebox 2 without a giant switch/case block. Also, Fusebox 2 had some specific file naming strategies which MVC doesn't require. Oh, that, and MVC is a million times more popular than Fusebox 2 - not to say that it's not used, I see it in every company I work for, and it drives me crazy.

On Feb 20, 2010 at 1:00 AM Steve Nelson ( or or said:
Well back when we created Fusebox 2 (12 years ago!) we didn't have fancy CFCs to work with. Hell, when I made Fusebox 1, cfswitch didn't even exist. The sheer fact that a framework can exist for a dozen years says a lot.

MrNate, your approach is skimming the surface of what MVC can really help with. Experiment and take it a few steps further. Try changing the cfms to cfcs. Try having more than just a "main" file and put multiple files in the three folders. Try subfolders. Try incorporating cfm files with the cfcs. You can keep your MVC framework simple, but it needs to be useful too.

Coming from the guy that invented the original Fusebox, here's the framework I've been using for the last few years. It's more of a methodology than a framework.

On Jul 23, 2010 at 1:00 AM huhu (hjute has underestimated the power of said:
how do u actually use this?
Too old to comment!