Creating user-defined functions
201
You must use
cfargument
tags for required function arguments. All
cfargument
tags must
precede any other CFML code in
cffunction
tag body. Therefore, put the
cfargument
tags
immediately following the
cffunction
opening tag. The
cfargument
tag takes the following
attributes:
Note:
The
cfargument
tag is not required for optional arguments. This feature is useful if a functions
can take an indeterminate number of arguments. If you do not use the
cfargument
tag for an optional
argument, reference it using its position in the Arguments scope array. For more information see
“Using the Arguments scope as an array” on page 196
.
roles
(Optional) A comma-delimited list of security roles that can invoke this method. If
you omit this attribute, ColdFusion does not restrict user access to the function.
If you use this attribute, the function executes only if the current user is logged in
using the
cfloginuser
tag and is a member of one or more of the roles specified in
the attribute. Otherwise, ColdFusion throws an unauthorized access exception. For
more information on user security, see
Chapter 16, “Securing Applications,”
on page 345
.
output
(Optional) Determines how ColdFusion processes displayable output in the function
body.
If you do not specify this option, ColdFusion treats the body of the function as normal
CFML. As a result, text and the result of any
cfoutput
tags in the function definition
body are displayed each time the function executes.
If you specify True or "yes", the body of the function is processed as if it were in a
cfoutput
tag. ColdFusion displays variable values and expression results if you
surround the variables and expressions with pound signs.
If you specify False or "no" the function is processed as if it were in a
cfsilent
tag.
The function does not display any output. The code that calls the function is
responsible for displaying any function results.
Attribute
Description
name
The argument name.
type
(Optional) The data type of the argument. The type of data that is passed to the function.
The valid standard type names are any, array, binary, boolean, date, guid, numeric,
query, string, struct, uuid, and variableName. If you specify any other name, ColdFusion
requires the argument to be a ColdFusion component with that name.
ColdFusion throws an error if you specify this attribute and the function is called with
data of a type that ColdFusion cannot automatically convert to the one you specified.
For example, if the argument
type
attribute is numeric, you cannot call the function with
an array.
required
(Optional) A Boolean value specifying whether the argument is required, If set to True
and the argument is omitted from the function call, ColdFusion throws an error. The
default is False.
Because you do not identify arguments when you call a function, all
cfargument
tags that
specify required arguments must precede any
cfargument
tags that specify optional
arguments in the
cffunction
definition.
default
(Optional) The default value for an optional argument if no argument value is passed.
If you specify this attribute, an error occurs if you specify this attribute and set the
required
attribute to True.
Attribute
Description
Summary of Contents for COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......