User Guide

Table Of Contents
212 Chapter 10: Building and Using ColdFusion Components
To run the example, display the tempConversion.cfm page in your browser. When you enter a
value in the text box of the form, the value is stored in the
form.temperature variable.
Processing is then performed on the processForm.cfm page, which refers to the value as
form.temperature. When you invoke either method, the cfinvoke tag assigns the value
form.temperature to temp; temp is the argument specified in the cfargument tag of the
appropriate method. The appropriate method in the
convertTemp component performs the
necessary calculations and returns the new value as
newtemp.
For detailed reference information on the
cfargument tag, see CFML Reference.
To access the parameter values in the component method definition, use structure- or array-like
notation with the Arguments scope. The following example refers to the
lastName argument as
Arguments.lastname; it could also refer to it as Arguments[1]. In addition, you can access
arguments directly using number (#) signs, such as
#lastname#; however, it is better
programming practice to identify the scope (for example,
#Arguments.lastname#). Also, you
can use Array- or structure-like notation, which lets you loop over multiple parameters.
For more information on the Arguments scope, see “The Arguments scope” on page 229.
To define parameters in the component method definition:
Create a new component with the following contents, and save it as corpQuery.cfc in a
directory under your web root directory:
<cfcomponent>
<cffunction name="getEmp">
<cfargument name="lastName" type="string" required="true"
hint="Employee last name">
<cfset var empQuery="">
<cfquery name="empQuery" datasource="cfdocexamples">
SELECT LASTNAME, FIRSTNAME, EMAIL
FROM tblEmployees
WHERE LASTNAME LIKE '#Arguments.lastName#'
</cfquery>
<!--- Use cfdump for debugging purposes. --->
<cfdump var=#empQuery#>
</cffunction>
<cffunction name="getCat" hint="Get items below specified cost">
<cfargument name="cost" type="numeric" required="true">
<cfset var catQuery="">
<cfquery name="catQuery" datasource="cfdocexamples">
SELECT ItemName, ItemDescription, ItemCost
FROM tblItems
WHERE ItemCost <= #Arguments.cost#
</cfquery>
<!--- Use cfdump for debugging purposes. --->
<cfdump var=#catQuery#>
</cffunction>
</cfcomponent>