I was building an app a few months ago and I wanted to pass around a series
of related variables.  What I had was a form for editing products.  I wanted
to pass around the variables to multiple places, but didnt want to hardcode
every variable as attributes when using cfmodule.  So what I decided to do
was name my form elements like so.

product.id
product.name
product.description

Then I modified formurl2attributes to search for a period in the form
variables.  If found it would then create a structure for that variable and
give it the appropriate keys, ie. id/name/description.  Then when passing
the variables around I only had to pass the structure.

The code was something like this...

<cfif isdefined("form.fieldnames")>
     <cfloop list="#form.fieldnames#" index="field">
            <cfif Find(".", field)>
                <cfset vTempVar = Mid(field,1,Find(".",field) - 1))>
                <cfif NOT IsDefined("#Evaluate(vTempVar)#")>
                    <cfset "#vTempVar#" = StructNew()>
                </cfif>
                <cfset "#field#" = Evaluate(field)>

            <!--- normal formurl2attributes code here --->

    </cfloop>
</cfif>

I just thru this down quick, didnt test it so it might not be accurate, I
also feel a little under the weather today.  But you get the point.  This
concept came to mind again recently when studying PHP, the PHP server does
this for you automatically.  I can see where it would be powerful.  Anyone
have any ideas/comments/suggestions?


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to