ColdFusion ORM Book

Really simple CMS with FW/1 and ColdFusion ORM

I recently wanted to create a simple, lightweight Content Managed site and decided to use FW/1 and of course ColdFusion's excellent ORM capabilities.

FW/1 is incredibly easy to get started with, you just need to download a single cfc and get Application.cfc to extend it.

As my site will have dynamic pages which can be added or deleted at any time, then I don't want to have to create specific views and controllers (as I don't know what the pages are yet!), luckily F/W1 has a onMissingView method which is called when a view is not found.

In the onMissingView I'm going use EntityLoad to get the page content from the database. To do that I'll need the define my Content object.

* I am the Content object which maps to the contents database table

component persistent="true" table="contents"
property name="id" column="content_id" generator="native";
property name="guid" column="content_guid"; // used for pretty urls
property name="title" column="content_title";
property name="content" column="content_content";

I'll need a view page to show the page content stored in the database.

I'm a simple view to display CMS content



It's a good idea to trap any requests to pages that no longer exist, so we need a 404 page.

I'm a simple 404 view

<h1>Page Not found</h1>
<p>Sorry, the page you requested (#getFullyQualifiedAction()#) has not been found.</p>

A layout would be kinda useful!

I am the default layout

<ul id="nav">
<cfloop array="" index="local.thispage">
<li><a href="#buildURL( local.thispage.getGuid() )#">#local.thispage.getTitle()#</a>

<div id="content">#body#</div>


Now we need to set up the Application.cfc

component extends="org.corfield.framework"

APPLICATION_ROOT = GetDirectoryFromPath( GetCurrentTemplatePath() ); = ReReplace( UCase( APPLICATION_ROOT ), "[^A-Z]", "", "all" );
this.mappings["/model"] = APPLICATION_ROOT & "model";

// ORM Setttings
this.datasource = "simplecms";
this.ormenabled = true;
this.ormSettings.flushAtRequestEnd = false;
this.ormSettings.cfclocation = this.mappings["/model"];

// FW/1 Setttings
variables.framework = {
generateSES = true

// executes when a view is not found
any function onMissingView( required rc )
var filter = {
guid = getFullyQualifiedAction()

rc.Content = EntityLoad( "Content", filter, true );
if ( !IsNull( rc.Content ) )
// use the content view to display content
return view( 'content' );
// create a 404 response header
var pc = getpagecontext().getresponse();
pc.getresponse().setstatus( 404 );
// set the page title
rc.Content = EntityNew( "Content" );
rc.Content.setTitle( "Page Not Found" );
// display the 404 page
return view( 'notfound' );

// executes per request
void function setupRequest()

// get all pages for the navigation = EntityLoad( "Content" );


Finally, we need to create a blank index.cfm file in the application root. Now when you hit a URL such as; http://localhost/simplecms/index.cfm/my-new-page. You'll get the 404 page. If you add a page to your database with the content_guid field set to "my-new-page.default", it will magically appear.

Obviously my application is more complex than this, but I thought it would be a good example of how simple it is to build a fairly powerful system quickly in ColdFusion and I haven't mentioned a beanFactory once!


  1. John, great example of how frameworks can handle complexity for you. Amazing how much ground you can cover in just a few dozen lines.

    What I find interesting is the fact that FW/1 accomplishes what it does while remaining just a single file. A sleek nutcracker to Hibernate's sledgehammer. But as your code shows, CF can do most of the heavy lifting and wielding of that sledgehammer for you.

    Comment by Julian Halliwell – May 23, 2011
  2. Hi Julian. What FW/1 does really well is build on-top of Coldfusion's in-built Application lifecycle.

    I could have made use of Service layers etc, but I really don't see the point for a simple app like this and the API for cf-orm is so nice :)

    Comment by John Whish – May 24, 2011
  3. how can i load categories in post form using coldfusion orm and fw1. Please help me out to let know the code.

    Comment by suleman khan – May 28, 2012
  4. @suleman, not sure I understand the question - if you want a list of categories on a form (say for a drop down), then you'd want to create a controller in FW/1 for the form, which calls:

    rc.categories = EntityLoad( "Category" );

    Then just loop over them in the view.

    Is that what you mean?

    Comment by John Whish – May 28, 2012
  5. @john, thanks for your reply.

    how can i do change password in coldfusion orm and fw1? can any body help me out to know this?

    Comment by suleman – June 18, 2012
  6. @suleman ORM doesn't have a password. FW/1 only uses a password to reload the application. If it's the FW/1 password you want then you can set it using variables.framework.password in you Application.cfc.

    Comment by John Whish – June 18, 2012
  7. hi john, actually i want to know how to implement change password or user data like we do in facebook or some other sites in account settings.

    can you help me out how to implement this?


    Comment by suleman – June 18, 2012
  8. @suleman - can I suggest that you have a look at a project my colleague Simon Bingham is working on called Xindi, which is a simple CMS built on FW/1 and ORM. You can download it from:

    The bit about handling password changes is here:

    Comment by John Whish – June 18, 2012
  9. i unable to delete comment, i m using this code to delete comment.

    <cffunction name="deleteComment" access="public" returntype="void">
       <cfargument name="rc" type="struct" required="true">
       <cfset var comment = getBlogService().comment(>
       <cfset getBlogService().DeleteComment(comment)>
       <cfset variables.fw.redirect( action = '', append = 'id' )>
    can anybody tell me whats wrong in it?


    Comment by suleman – June 18, 2012

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.

Please subscribe me to any further comments


Wish List

Found something helpful & want to say ’thanks‘? Then visit my Amazon Wish List :)


Recent Posts