Expressions
43
You use built-in functions throughout ColdFusion pages. Built-in functions are frequently used
in a
cfset
or
cfoutput
tag to prepare data for display or further use. For example, the following
line displays today’s date in the format October 12, 2001:
<cfoutput>#DateFormat(Now(), "mmmm d, yyyy")#</cfoutput>
Note that this code uses two
nested
functions. The
Now
function returns a ColdFusion date-time
value representing the current date and time. The
DateFormat
function takes the value returned
by the
Now
function and converts it to the desired string representation.
Functions are also valuable in CFScript scripts. ColdFusion does not support ColdFusion tags in
CFScript, so you must use functions to access ColdFusion functionality in scripts.
User-defined functions
You can write your own functions,
user-defined functions
(UDFs). You can use these functions in
ColdFusion expressions or in CFScript. You can call a user-defined function anywhere you can
use a built-in CFML function. You create UDFs using the
cffunction
tag or the CFScript
function
statement. UDFs that you create using the
cffunction
tag can include ColdFusion
tags and functions. UDFs that you create in CFScript can only include functions.
User-defined functions let you encapsulate logic and operations that you use frequently in a single
unit. This way, you can write the code once and use it multiple times. UDFs ensure consistency of
coding and enable you to structure your CFML more efficiently.
Typical user-defined functions include mathematical routines, such as a function to calculate the
logarithm of a number; string manipulation routines, such as a function to convert a numeric
monetary value to a string such as “two dollars and three cents”; and can even include encryption
and decryption routines.
Note:
The Common Function Library Project at http://www.cflib.org includes a number of free
libraries of user-defined functions.
For more information on user-defined functions, see
Chapter 10, “Writing and Calling User-
Defined Functions,” on page 191
.
Expressions
ColdFusion
expressions
consist of
operands
and
operators
. Operands are comprised of constants and
variables, such as “Hello” or MyVariable. Operators, such as the string concatenation operator
(&) or the division operator (/) are the verbs that act on the operands. ColdFusion functions also
act as operators.
The simplest expression consists of a single operand with no operators. Complex expressions
consist of multiple operands and operators. For example, the following statements are all
ColdFusion expressions:
12
MyVariable
(1 + 1)/2
"father" & "Mother"
Form.divisor/Form.dividend
Round(3.14159)
The following sections briefly describe constants and variables. For detailed information on using
variables, see
Chapter 3, “Using ColdFusion Variables,” on page 53
. For detailed information on
expressions and operators, see
Chapter 4, “Using Expressions and Pound Signs,” on page 83
.
Содержание COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...