Creating your first Coldfusion Component Step 3
Coldfusion Component Step 3
So far I have shown faily simple items for CFC's. Today we will learn about the argument tag. By using this robust tag we have become empowered. This tag allows us to pass data!
VERY IMPORTANT NOTE: If you use the <cfargument> tag it HAS to be the first tag in the function. Even if you are using mulitple arguments in the same function
Define:
cfargument: used in the <cffunction> tag to define arguments tag: <cfargument name ="argument name"
displayname="descriptive name"
hint="Extended Descriptive String"
type="Data Type of argument"
Required="Yes/No"
Default="Default value of argument">
Attrubutes
Name: required
Type: optional
Required: optional, default is no
default: data value
Values of the TYPE attribute include
Any Boolean
GUID
String
Array
Component Name
Numeric
Struct
Binary
Date
Query
UUID
Variable Name
XML
Example 3
<!--- Perform geometric calculations --->
<cffunction name="geometry" returntype="struct">
<!--- Need a radius --->
<cfargument name="radius" type="numeric" required="yes">
<!--- Define result variable --->
<cfset var result=StructNew()>
<!--- Save radius --->
<cfset result.radius=radius>
<!--- First circle --->
<cfset result.circle=StructNew()>
<!--- Calculate circle circumference --->
<cfset result.circle.circumference=2*Pi()*radius>
<!--- Calculate circle area --->
<cfset result.circle.area=Pi()*(radius^2)>
<!--- Now sphere --->
<cfset result.sphere=StructNew()>
<!--- Calculate sphere volume --->
<cfset result.sphere.volume=(4/3)*Pi()*(radius^3)>
<!--- Calculate sphere surface area --->
<cfset result.sphere.surface=4*result.circle.area>
<!--- Return it --->
<cfreturn result>
</cffunction>

Recent comments
11 weeks 3 days ago
11 weeks 3 days ago
14 weeks 6 days ago
15 weeks 4 days ago
15 weeks 4 days ago
17 weeks 5 days ago
30 weeks 4 days ago
30 weeks 4 days ago
30 weeks 6 days ago
31 weeks 13 hours ago