User Guide

Table Of Contents
Creating ColdFusion components 209
Defining and using method parameters
You pass data to a method by using parameters. To define a component method parameter, use
the
cfargument tag in the cffunction tag body. To define multiple parameters, use multiple
cfargument tags. The tag names a parameter and lets you specify the following:
Whether the parameter is required
The type of data that is required
A default argument value
Display name and hint metadata for CFC introspection
Note: You can create CFC methods that do not use cfargument tags, for example, if you use
positional parameters in your methods. However, most CFC methods use the
cfargument tag.
Example: convertTemp.cfc
The convertTemp.cfc file consists of the following:
<cfcomponent>
<!--- Celsius to Fahrenheit conversion method. --->
<cffunction name="ctof" output="false">
<cfargument name="temp" required="yes" type="numeric">
<cfreturn ((temp*9)/5)+32>
</cffunction>
<!--- Fahrenheit to Celsius conversion method. --->
<cffunction name="ftoc" output="false">
<cfargument name="temp" required="yes" type="numeric">
<cfreturn ((temp-32)*5/9)>
</cffunction>
</cfcomponent>
Reviewing the code
The convertTemp CFC contains two methods that convert temperature. The following table
describes the code and its function:
Code Description
<cfcomponent>
Defines the component.
<cffunction name="ctof"
output="false">
Defines the ctof method.
Indicates that this method does not display output.
<cfargument name="temp"
required="yes" type="numeric">
Creates the temp parameter of the ctof method. Indicates that
it is required and that the expected value is
numeric.
<cfreturn ((temp*9)/5)+32>
Defines the value that the method returns.
</cffunction>
Ends the method definition.
<cffunction name="ftoc"
output="false">
Defines the ftoc method.
Indicates that this method does not display output.
<cfargument name="temp"
required="yes" type="numeric">
Creates the temp parameter of the ftoc method. Indicates that
it is required and that the expected value is
numeric.