DREAMWEAVER CS3
User Guide
666
A CFC is a reusable software unit written in ColdFusion markup language (CFML), which makes it easy to reuse and
maintain your code.
You can use Dreamweaver to work with CFCs. For information on CFC tags and syntax, see the ColdFusion
documentation from within Dreamweaver (Help > Using ColdFusion).
Note:
You can use CFCs only with ColdFusion MX or later. CFCs are not supported in ColdFusion 5.
CFCs are meant to provide a simple yet powerful way for developers to encapsulate elements of their websites.
Generally, you should use components for application or business logic. Use customs tags for presentation elements
such as customized greetings, dynamic menus, and so on.
As with many other types of construction, dynamic sites can often benefit from interchangeable parts. For example,
a dynamic site may run the same query repeatedly, or calculate the total price of shopping cart pages and recalculate
it every time an item is added. These tasks can be handled by components. You can fix, improve, extend, and even
replace a component with minimal impact to the rest of your application.
Suppose an online store calculates shipping charges based on the price of orders. For orders under $20, the shipping
charge is $4; for orders between $20 and $40, the shipping charge is $6, and so on. You could insert the logic for calcu-
lating the shipping charge in both the shopping cart page and the checkout page, but that would mix HTML presen-
tation code and CFML logic code and generally make the code difficult to maintain and reuse.
You decide to create a CFC called Pricing that has, among other things, a function called
ShippingCharge
. The
function takes a price as an argument and returns a shipping charge. For example, if the value of the argument is
32.80, the function returns 6.
In both the shopping cart page and the checkout page, you insert a special tag to invoke the
ShippingCharge
function. When the page is requested, the function is invoked and a shipping charge is returned to the page.
Later, the store announces a special promotion: free shipping for all orders above $100. You make the change to the
shipping rates in one place—the
ShippingCharge
function of the Pricing component—and all the pages using the
function automatically get accurate shipping charges.
Components panel overview (ColdFusion)
Use the Components panel (Window > Components) to view and edit ColdFusion components, and add code in the
page that invokes the function when the CFM page is requested.
Note:
The Components panel is available only when viewing a ColdFusion page in Dreamweaver.
See also
“Build web pages that use CFCs” on page 669
Create or delete a CFC in Dreamweaver
You can use Dreamweaver to visually define a CFC and its functions. Dreamweaver creates a .cfc file and inserts the
necessary CFML tags for you.
Note:
Depending on the component, you may have to complete some code by hand.
1
Open a ColdFusion page in Dreamweaver.
2
In the Components panel (Window > Components), select CF Components from the pop-up menu.
September 4, 2007