Adobe COLDFUSION 9 Manual page 185

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
• You use the cffunction tag to define CFC methods. The CFScript
but it does not provide options to control access to the method, provide metadata, specify a return type, or control
generated output.
• You can write code on the component page that is outside
CFC is instantiated or whenever you invoke a method of the CFC.
Building ColdFusion components
You use the cfcomponent and cffunction tags to create ColdFusion components. By itself, the
not provide functionality. The
in CFML and enclose in
cffunction
methods:
<cfcomponent>
<cffunction name="firstMethod">
<!--- CFML code for this method goes here. --->
</cffunction>
<cffunction name="secondMethod">
<!--- CFML code for this method goes here. --->
</cffunction>
</cfcomponent>
Defining component methods
You define component methods using cffunction tags. The following example defines a CFC that contains two
methods,
and
getall
getsalary
<cfcomponent>
<cffunction name="getall" output="false" returntype="query">
<cfset var queryall="">
<cfquery name="queryall" datasource="cfdocexamples">
SELECT * FROM EMPLOYEE
</cfquery>
<cfreturn queryall>
</cffunction>
<cffunction name="getsalary" output="false">
<cfset var getNamesandSalary="">
<cfquery name="getNamesandSalary" datasource="cfdocexamples">
SELECT FirstName, LastName, Salary FROM EMPLOYEE
</cfquery>
<cfreturn getNamesandSalary>
</cffunction>
</cfcomponent>
Because component methods are ColdFusion functions, most of their features and coding techniques are identical to
those of user-defined functions. For more information on using the
and Calling User-Defined
Functions" on page 153. Like other ColdFusion functions, CFC methods can display
information directly by generating output, or can return a value to the code or client that invoked the method.
You use the following
cffunction
• The
and
displayname
hint
on page 187.
• The
attribute, which controls access to the CFC; for more information, see
access
page 204.
tag provides an envelope that describes the functionality that you build
cfcomponent
tags. The following example shows the skeleton of a component with two
:
tag attributes only for CFCs:
attributes, which document the CFC; for more information, see
Last updated 8/5/2010
statement can create simple methods,
function
definitions. This code executes when the
cffunction
tag to create functions, see
cffunction
"Using access
180
tag does
cffunction
"Writing
"Documenting
CFCs"
security" on

Advertisement

Table of Contents
loading

Table of Contents