> Can I ask what you mean when you say scope your variables?
> can you give an example, even this one here, how could I scope
> your variables with this example?

Sure thing.  A variable "scope" in ColdFusion can be described as a
container of category for a group of variables.  For example, if you
have a page that is called on its URL as:

http://example.com/test-page.cfm?some_variable=myValue

You would output that variable in the code as follows:

<cfoutput>#url.some_variable#</cfoutput>

Here it would be referred to accessing that variable in the "url"
scope.  Similarly, there is a "form" scope for variables passed in for
a form post.

ColdFusion has a number of other variable scopes (or containers) for
data coming from the web server (cgi scope), function arguments
(arguments scope), global request variables (request scope),
application variables which persist as long as the application is
running (application scope), session variables which persist per user
session (session scope), and so on.

In the URL example above, you COULD access that variable by simply
outputting #some_variable# (without the leading "url.") and ColdFusion
would search through most of its internal variable scopes to locate
that value in the URL scope, and then display it without error.

The scopes are used to remove any ambiguity about which variable you
want to access.  It is entirely possible to have a variable called
"id" which may exist in multiple scopes at once (for example:
variables.id for a locally defined variable [<cfset id=1>], url.id for
a value passed on the url, and form.id for a value passed in a form).

It is always best practice to specify which variable scope you want to
get the variable from to remove any ambiguity in your code (#id# could
mean the id variable from any of the scopes ColdFusion searches
through).  It would be better to specify #variables.id# or #url.id# or
#form.id# depending on which one you want your code to look at.

Some scopes, such as application, session, and request are not
automatically searched and must always be explicitly called (as you
discovered earlier).

If you have any other questions please feel free to ask.  That's why we're here!


-Justin Scott

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-newbie/message.cfm/messageid:5759
Subscription: http://www.houseoffusion.com/groups/cf-newbie/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-newbie/unsubscribe.cfm

Reply via email to