User Guide

Table Of Contents
201
CHAPTER 10
Building and Using ColdFusion Components
This chapter describes Macromedia ColdFusion component (CFC) concepts and elements and
tells you how to create and use CFCs. It provides you with all the tools to create and use CFCs;
however, it does not discuss CFC methodologies or provide information on designing
applications for CFC use. For more information on creating applications that use CFCs, see the
Macromedia website: www.macromedia.com.
Contents
About ColdFusion components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Creating ColdFusion components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Using ColdFusion components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Passing parameters to methods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Using CFCs effectively. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
ColdFusion component example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
About ColdFusion components
A ColdFusion component (CFC) is a file saved with the extension .cfc. A CFC can contain data
and functions. Within a CFC, data is referred to as properties. Although you use the
cffunction
tag to define functions within a CFC, they are typically referred to as methods instead of
functions.
The page on which you define a CFC is also known as a component page. Component pages use
the same tags and functions that regular CFML pages do, plus a small number of special tags (in
particular, the
cfcomponent tag) and tag attributes.
You define related methods in a CFC. Unlike ColdFusion custom tags, a single CFC can perform
many related actions, defined in multiple methods. The methods may share a data context, such
as metadata and scoping, or manage a particular database or set of tables. For example, you can
define the methods to insert, update, delete, and retrieve records from a particular database or
table in one CFC.