[thelist] CF: form. Url. Attributes. A better way?

jeff jeff at members.evolt.org
Sun Jan 14 21:01:31 CST 2001


: From: Frank
: I'm trying to create scheme where everything
: is pretty modular, almost object oriented. I
: break my queries apart from the logic, so that
: any number of display modules can call to them.

this makes sense so long as you don't take it too far.  for example, if all
the files necessary for a given module/application aren't easily
distinguishable and therefore easily packaged up for movement to somewhere
else, then you're only inviting trouble.  it certainly makes sense to
separate your queries from the display logic, but only to a point.

: What I tend to end up doing it this:
: <cfif IsDefined("URL.ID")>
:     <cfset TheID = "#URL.ID#">
: <cfelsif IsDefined("Form.ID")>
:     <cfset TheID = "#Form.ID#">
: <cfelseif IsDefined("Attributes.ID")>
:     <cfset TheID = "#Attributes.ID#">
: </cfif>
: Use: #TheID#
: This seems rather clumsy to me.

it seems clumsy cause it is.

: Does anyone have a better of getting
: the correct scope for a variable without
: having to redefine them each time on
: every query?

for one, the solution will be on a case by case basis.  some apps will
expect the variable to come from the url.  others will expect it to come
from a form post.  for those apps that are only expecting it from one or the
other, then set it up to use the scope it's expecting it from.  for those
apps that are expecting it from either form or url, then my suggestion would
be to refer to it as an unscoped variable.

now, there are some additional things i'd like to address regarding your
code above.  when defining the value of a variable from another variable
using cfset, the hashes are unnecessary if you don't wrap the value in
double-quotes.  for those with syntax highlighting it's easier to tell that
you're setting it to the value of another variable.

<cfset TheID = url.id>

one final point i'd like to make is about the attributes scope.  this isn't
a scope that you can just use anywhere within your application as a genuine
scope.  the only time when it's a valid scope is *within* a custom tag or
cfmodule, and then only to refer to those values that are passed in via the
attributes of the custom tag or cfmodule.  outside of a custom tag or
cfmodule appending your variables with "attributes." is simply creating a
new variable with a dot in the name.  you do not gain the advantage of
scoping a variable by doing this.

i like the suggestion that joshua made about formurl2attributes custom tag
from fusebox.org.  however, i would suggest that you look it over and
rewrite it to initialize a valid struct and add keys to that struct for the
variables from the form and url scope, instead of the attributes "scope" as
it's doing now.

good luck,


mailto:jeff at members.evolt.org

More information about the thelist mailing list