
58
DEVELOPING
COLDFUSION 9 APPLICATIONS
The CFML Programming Language
Las
t
upda
te
d 8/5/2010
Important:
To prevent data corruption, you lock code that uses Session, Application, or Server scope variables. For more
information, see “
Using Persistent Data and Locking
” on page
301.
Creating and using variables in scopes
The following table shows how you create and reference variables in different scopes in your code. For more
information on the mechanisms for creating variables in most scopes, see “
Creating variables
” on page 39.
thread local
Variables that are available only within a ColdFusion thread. For more information, see “
Using ColdFusion
Threads
” on page
328.
URL
Contains parameters passed to the current page in the URL that is used to call it. The parameters are appended to
the URL in the format ?variablename = value[&variablename=value...]; for example
www.MyCompany.com/inputpage.cfm?productCode=A12CD1510&quantity=3.
If a URL includes multiple parameters with the same name, the resulting variable in the ColdFusion URL scope
consists of all parameter values separated by commas. For example, a URL of the form
http://localhost/urlparamtest.cfm? param=1¶m=2¶m=3 results in a URL.param variable value of 1,2,3
on the ColdFusion page.
Variables
The default scope for variables of any type that are created with the
cfset
and
cfparam
tags. A Variables scope
variable is available only on the page on which it is created and any included pages (see also the Caller scope).
Variables scope variables created in a CFC are available only to the component and its functions, and not to the
page that instantiates the component or calls its functions.
Scope prefix
(type)
Prefix required to
reference
Where available
Created by
Application
Yes
For multiple clients in one application over
multiple browser sessions. Surround code that
uses application variables in
cflock
blocks.
Specifying the prefix Application when you
create the variable.
Arguments
No
Within the body of a user-defined function or
ColdFusion component method.
The calling page passing an argument in the
function call.
Attributes
Yes
On a custom tag page, or inside a thread
For custom tags, the calling page passing the
values to a custom tag page in the custom tag’s
attributes.
For threads, the
cfthread
tag specifying
attribute values.
Caller
On the custom tag
page, Yes.
On the calling page,
No (Variables prefix
is optional).
On the custom tag page, by using the Caller
scope prefix.
On the page that calls the custom tag, as local
variables (Variables scope).
On the custom tag page, by specifying the prefix
Caller when you create the variable.
On the calling page, by specifying the prefix
Variables, or using no prefix, when you create
the variable.
Cffile
Yes
Following an invocation of
cffile
.
A cffile tag.
CGI
No
On any page. Values are specific to the latest
browser request.
The web server. Contains the server
environment variables that result from the
browser request.
Client
No
For one client in one application, over multiple
browser sessions.
Specifying the prefix Client when you create the
variable.
Cookie
No
For one client in one or more applications and
pages, over multiple browser sessions.
A cfcookie tag. You can also set memory-only
cookies by specifying the prefix Cookie when
you create the variable.
Scope Description