
14
Chapter 2 Writing Your First ColdFusion Application
you can write:
I’d like to talk to someone in #Variables.Department#.
Some variable scopes, such as the local scope, do not require the scope identifier
prefix, while others do. However, it is good programming practice to use prefixes for
most or all scopes. This helps to better identify each variable’s use and can prevent
multiple uses of the same name. This book uses the scope prefix for all variables
except for local variables.
The following table lists some of the more common types of variable scopes and the
prefixes that you use to identify the variables. Other chapters in this book discuss
additional scope types. The CFML Reference has a complete list of scope types, their
identifiers, and how they are used.
Using the pound sign (#)
You surround a ColdFusion variable or function with pound signs (#) to tell the
ColdFusion Server that it is not plain text. You only need to use pound signs in
limited circumstances, particularly in the
cfoutput and
cfquery
tag blocks. You do
not need to use pound signs when you create a variable, assign it a value, or use it in
a ColdFusion expression or as a parameter in a ColdFusion function.
Note
Remember that ColdFusion cannot interpret anything, including variables, that is
not inside a ColdFusion tag or tag block.
The following table illustrates the basic use of pound signs. For a detailed description
of the use of pound signs, see CFML Reference.
Scope type
Prefix
Description
Local (or
Variables)
Variables
Variables created using cfset or cfparam, with or without
specifying the scope prefix. You must define the variable
on the current page or a page you include using
cfinclude
.
Form
Form
Data entered in tags in an HTML form or ColdFusion
cfform
tag block and processed on an action page.
URL
URL
Variables passed to a page as URL query string
parameters.
CFML code
Results
cfset Department="Sales">
The variable named Department is created
and the value is set to Sales.
<cfoutput>
I’d like to talk to someone in
Department.
</cfoutput>
ColdFusion does not treat Department as a
variable because it is not surrounded by
pound signs. The HTML page displays:
I’d like to talk to someone in Department.
Содержание COLDFUSION 5-DEVELOPING
Страница 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Страница 58: ...38 Chapter 3 Querying a Database ...
Страница 134: ...114 Chapter 7 Updating Your Database ...
Страница 210: ...190 Chapter 10 Reusing Code ...
Страница 232: ...212 Chapter 11 Preventing and Handling Errors ...
Страница 238: ...218 Chapter 12 Using the Application Framework ...
Страница 262: ...242 Chapter 12 Using the Application Framework ...
Страница 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Страница 320: ...300 Chapter 15 Indexing and Searching Data ...
Страница 336: ...316 Chapter 16 Sending and Receiving E mail ...
Страница 374: ...354 Chapter 18 Interacting with Remote Servers ...