Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 191

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
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
refer to it as
. In addition, you can access arguments directly using number (#) signs, such as
Arguments[1]
; however, it is better programming practice to identify the scope (for example,
#lastname#
. Also, you can use Array- or structure-like notation, which lets you loop over multiple
#Arguments.lastname#)
parameters.
For more information on the Arguments scope, see
Define parameters in the component method definition
Create a 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>
In the example, the
cfargument
• The
attributes define the parameter names.
name
• The
attribute for the
type
for the
argument specifies that the parameter must be a numeric value. These attributes validate the data
cost
before it is submitted to the database.
• The
attributes indicate that the parameters are required, if not, ColdFusion throws an exception.
required
• The Arguments scope provides access to the parameter values.
Providing results
ColdFusion components can provide information in the following ways:
• They can generate output that is displayed on the calling page.
• They can return a variable.
lastName
"The Arguments
attributes specify the following:
argument specifies that the parameter must be a text string. The
lastName
Last updated 1/20/2012
argument as
Arguments.lastname
scope" on page 200.
186
; it could also
attribute
type

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents