The Dopefly Tech Blog

« The Dopefly Tech Blog Main page

Easiest Ever MVC with ColdFusion

posted under category: ColdFusion on February 17, 2010 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.

/app/index.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.

Nathan is a software developer at The Boeing Company in Charleston, SC. He is essentially a big programming nerd. Really, you could say that makes him a nerd among nerds. Aside from making software for the web, he plays with tech toys and likes to think about programming's big picture while speaking at conferences and generally impressing people with massive nerdiness and straight-faced sarcastic humor. Nathan got his programming start writing batch files in DOS. It should go without saying, but these thought and opinions have nothing to do with Boeing in any way.
This blog is also available as an RSS 2.0 feed. Click your heels together and click here to contact Nathan.