Home > ColdFusion, Web Application Development > Learning CFWheels – progress

Learning CFWheels – progress

I have gotten CFWheels installed and I dove right into the documentation and tutorials.  I must admit, some of this OOP stuff is actually starting to click with me.  While working through some of the tutorials, I was thinking in  terms of applications I’ve worked on and tried to figure out how to recreate some old projects in CFWheels.  I posted a question in the CFWheels Google group but I thought I’d post it here as well to see if perhaps I’m just using bad practices or get feedback on a better way to do things.  So here goes.

While not an OO programmer, I use CFCs pretty heavily.  One thing that we always use in our development is a lookup CFC.  This contains various methods that are queries to tables that contain mostly static data.  This could be a states or countries table, or perhaps a table of possible responses for a drop down list or radio button group.  They are usually to drive form elements.   I was working through the users tutorial in the CFWheels documentation and wanted to expand on it to include a states drop down in the add and edit forms.  I got to wondering, do I have to create a controller/states.cfc just for a states object in CFWheels along with it’s view/states/index.cfm?  If not, where would I place a the findall() to retrieve the list for placement in a form?  I managed to get it to work by placing <cfset states =

In my normal development, my form might look like:

<cfloop query="departments">
      <option value="#departments.id#"<cfif profile.departmentId eq departments.id> selected="selected"</cfif>>#departments.name#</option>
</cfloop>

Do I need an index method in a states.cfc that has my findAll() and an empty views/states/index.cfm?  Or is there another generally accepted way to do this?

Advertisements
  1. July 20, 2010 at 10:31 am

    You don’t need a model, view or controller file as long as your tables are using the Wheels database conventions.If you just wanted to retrieve all the states from their corresponding table, this should work

    <cfset mystates=model("state").findAll()>

    You could place in any CFM file, and then use the 'mystates' query object as you would normally.

    I think you could even do:

    #selectTag(name="State", options=mystates, label="State:")#

    to create your form element, and skip using CFLOOP altogether.

    That's the beauty of CFWheels. You can implement it in pieces, rather than an all-or-nothing approach, which is especially handy if you are add Wheels to an existing application.

    I'm rather new to it myself, but I'm really excited about retrofitting Wheels into some of my old apps, and using it in new ones.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: