
183
DEVELOPING
COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Las
t
upda
te
d 8/5/2010
<cfcomponent displayname="shoppingCart">
<cffunction name="init" access="public" output="no" returntype="shoppingCart">
<cfargument name="shoppingCartID" type="UUID" required="yes">
<cfset variables.shoppingCartID = arguments.shoppingCartID>
<cfreturn this>
</cffunction>
<!--- Additional methods go here. --->
</cfcomponent>
In this example, the
init()
method uses the variables scope to make the shopping cart ID available anywhere in the
CFC. For more information about scope, see “
CFC variables and scope
” on page 198.
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:
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...