Using Components

Now that you understand how to create a basic component, let’s discuss how to use them in your applications. Typically, you create an instance of a component and then call a method on it, passing data in the form of arguments. The component does something based on the arguments passed and may return data to the calling page. That’s component interaction in a nutshell. You have quite a bit of choice, however, in how you make it all work. There are seven basic ways in which you can call a component. These include the following:

cfinvoke tag

Instantiates a CFC and/or invokes a method on an instantiated CFC.

cfobject tag

Instantiates a CFC. Properties must be explicitly set, and methods explicitly called.

createObject( ) function

Instantiates an object via cfset, cfparam, or cfscript. Properties must be explicitly set, and methods explicitly called.


Invokes a component method directly via an HTTP GET. The CFC filename is specified in the URL along with the method name as a URL parameter.

Form post

The Action attribute of an HTML form or cfform tag posts directly to a CFC. The method to call must be specified by a form field.

Web service

CFCs can be consumed as web services. For more information, see Chapter 24.

Flash Remoting

Flash MX animations can call ColdFusion components via Flash Remoting. For more information, see Chapter 28.

Using cfinvoke

In an effort to make working with CFCs and methods as simple as possible, let’s break each of these techniques down. ...

Get Programming ColdFusion MX, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.