O'Reilly logo

Programming ColdFusion MX, 2nd Edition by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Components

Creating a CFC is easy. You simply define the component using the cfcomponent tag and save the file with a .cfc extension. cfcomponent is a paired tag that acts as a container for the CFC. Within the component, you can have any number of properties (defined by the cfproperty tag) and methods (each defined using a pair of cffunction tags). Each method can accept zero or more arguments, defined with cfargument tags. If a CFC returns any data, it does so with the cfreturn tag. Essentially, a component is a collection of related UDFs grouped within a cfcomponent container. Syntactically, a basic CFC looks like this:

<cfcomponent>
  <cfproperty />
  
  constructor code...
   
  <cffunction>
    <cfargument>
    CFML
    <cfreturn>
  </cffunction>
   
  <cffunction>
    <cfargument>
    CFML
    <cfreturn>
  </cffunction>
</cfcomponet>

The cfcomponent tag has four optional attributes:

displayname=" display_name "

Used to display a descriptive name for the component in ColdFusion MX’s Component Browser or when the component is introspected using the getMetaData( ) function. These concepts are discussed later in the chapter.

hint=" text "

Used to display a hint describing what the component does in ColdFusion MX’s Component Browser or when the component is introspected using the getMetaData( ) function.

extends=" component_name "

Name of a parent component from which the component should inherit methods and properties.

output="yes|no"

Indicates whether the component’s constructor code (any area within the

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required