Andrew Clarke

systems architect, internet developer, team leader

Andrew Clarke

CFScaffold

I'll be putting documentation here for CFScaffold as I write it.  Look over in the right column for pages describing the use of specific components.  Some details in this documentation may refer to unreleased features of CFScaffold.  If you run into things that don't seem to work, please contact me.

Requirements

Adobe ColdFusion 9+, or Railo 3.2+.  CFScaffold won't run on older versions of either engine as it relies on the ORM implementation that wasn't introduced to Adobe ColdFusion until version 9.  CFScaffold may require ColdFusion 9.01; I haven't tried it on ColdFusion 9.0.

I use CFScaffold on Mac OS X and Microsoft Windows.  I haven't run it yet under Linux but it "should" run.

Setup

1. Download CFScaffold from http://cfscaffold.riaforge.org.

2. Unzip it into a directory, which we'll call <cfscaffold_home> here.

3. Make a mapping to /ca in your CFML engine administrator, pointing to <cfscaffold_home>/ca , or wherever you decide to move the <cfscaffold_home>/ca directory to.  If you already have a /ca mapping, really what's needed for CFScaffold is a mapping to /ca/clarke.

4. Modify settings.ini if necessary.  I've created a separate page for this at http://www.clarke.ca/page.cfm/projects/cfscaffold/settings.

5. Ensure that upstream of CFScaffold is an Application.cfc with your ORM settings.  CFScaffold uses ORM, so you have to have all that set up for CFScaffold.

6. Make sure that application.factory is instantiated.  The code to do this is in index.cfm, so if you're running CFScaffold from index.cfm you'll be fine.  Otherwise, if you're calling CFScaffold's functions directly in your code, make sure you set up application.factory and the associated code somewhere beforehand.

Usage

There are two basic ways to use CFScaffold: as an application of its own, or by calling it from your own code.

CFScaffold as an application

This is the way the demo works at http://www.clarke.ca/cfscaffold/examples/index.cfm.  That page links to two different demos, a default one and an advanced one.  You can call index.cfm with various parameters to display various pages, but the CFScaffold will always return to itself at index.cfm.  This is useful if you need a quick admin console, for example.

Calling from your own code

See the code for the advanced example to see this in action.  To call CFSCaffold from your own code, you first have to have instantiated application.factory using the code in index.cfm.  Once you've done that, you can display a page by running the following code:

application.factory.getObject("CFScaffold").doAction(action, entityName, entityID, metaData);

 

The actions are: create, delete, display, edit, list, save.  The entityName is the name of your entity, i.e. "Person", or "Address".  The entityID is the primary key of the entity upon which you wish to act, and metaData allows you to pass in a MetaData object, pre-populated with specifically how you want this action to behave (more on that later).

Examples:

application.factory.getObject("CFScaffold").doAction();

The default action is to list all the entities.

application.factory.getObject("CFScaffold").doAction(action="edit"entityName="Person"entityID=4);

Display the "edit" page for Person 4.

application.factory.getObject("CFScaffold").doAction(action="edit"entityName="Person");

This will display the form to create a new Person.

The MetaData object is pretty sparse right now, but later on it will let you do things like set your own layout templates, destination URLs, and parameters for form elements.

You can also call a layout or an "action content" page directly.  If you're reading this, this means I haven't written the documentation for it yet.  If you want to do this, please let me know.

EntitySmartList

Documentation for Greg Moser's EntitySmartList can be found at https://github.com/gregmoser/entitySmartList/wiki.  Whenever CFScaffold gets a list of objects from the database, it uses EntitySmartList.  This means that you can pass parameters to your URLs in order to narrow down the list of objects returned, sort them in a specific way, etc.  Please see the EntitySmartList documentation for more information, but here's an example of how to display a list of provinces & states, in descending order of two-digit code: http://www.clarke.ca/cfscaffold/index.cfm?entityName=ProvinceState&orderBy=code|D.

 

 

 

31 Comments

31 responses so far ↓

  • 1 Eric // Jul 27, 2011 at 1:39 PM

    Thank you for creating such a wonderful tool! I just can't figure out a couple things:

    When I first ran cfscaffold it tried to instantiate an object called "Account" which didn't exist in the ORM models. So, I created one, and then I figured out that I needed to add an "id" to the Account table. That being done, it got farther down the page.

    Then, later it said the "messager" variable didn't exist. I commented out that line in the code and it works.

    Any ideas what's going on?

    Railo 3.2, H2 database

Leave a Comment

Leave this field empty