Adobe COLDFUSION 9 Manual page 66

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
The Java
Response interface method and C++
setVariable
Variables scope of the calling page. Therefore, they are equivalent to setting a Caller scope variable in a custom
ColdFusion tag.
Using scopes as structures
ColdFusion makes all named scopes available as structures. You cannot access the function-local scope for user-
defined functions (UDFs) that you define using CFScript as a structure.
You can reference the variables in named scopes as elements of a structure. To do so, specify the scope name as the
structure name and the variable name as the key. For example, if you have a MyVar variable in the Request scope, you
can reference it in either of the following ways:
Request.MyVar
Request["MyVar"]
Similarly, you can use CFML structure functions to manipulate the contents of the scope. For more information on
using structures, see
"Using Arrays and
Important: Do not call
StructClear(Session)
built-in variables, effectively ending the session. If you want to use
CFtoken
variables, place those variables in a structure in the Session scope, and then clear that structure. For example, place all
your application variables in Session.MyVars and then call
Ensuring variable existence
ColdFusion generates an error if you try to use a variable value that does not exist. Therefore, before you use any
variable whose value is assigned dynamically, you must ensure that a variable value exists. For example, if your
application has a form, it must use some combination of requiring users to submit data in fields, providing default
values for fields, and checking for the existence of field variable values before they are used.
There are several ways to ensure that a variable exists before you use it, including the following:
• You can use the
IsDefined
• You can use the
cfparam
• You can use a
tag with a
cfinput
does not enter data in a required field. For more information on this technique, see
in form
fields" on page 709.
Testing for a variable's existence
Before relying on a variable's existence in an application page, you can test to see if it exists by using the
function. To check whether a specific entry exists in an array, use the
specific key exists in a structure, use the StructKeyExists function.
For example, if you submit a form with an unsettled check box, the action page does not get a variable for the check
box. The following example from a form action page makes sure the Contractor check box Form variable exists before
using it:
<cfif IsDefined("Form.Contractor")>
<cfoutput>Contractor: #Form.Contractor#</cfoutput>
</cfif>
You must always enclose the argument passed to the
on the
function, see the CFML Reference.
IsDefined
Structures" on page 82.
to clear session variables. This deletes the
function to test for the variable's existence.
tag to test for a variable and set it to a default value if it does not exist.
attribute to tell ColdFusion to display a helpful message to any user who
hidden
IsDefined
Last updated 8/5/2010
method return data to the
CCFX::SetVariable
StructClear
StructClear(Session.MyVars)
"Requiring users to enter values
ArrayIsDefined
function in quotation marks. For more information
,
, and
SessionID
CFID
to delete your application
to clear the variables.
IsDefined
function. To check whether a
61

Advertisement

Table of Contents
loading

Table of Contents