Invoking CFC methods with the cfinvoke tag
The
tag can invoke CFC methods transiently or invoke methods on a CFC instance.
cfinvoke
You can also use the
Invoking component methods transiently using the cfinvoke tag
In ColdFusion pages or components, the
creating a persistent CFC instance.
To invoke a component method transiently, use the
•
The name or path of the component, in the
•
The method name, in the
•
Any parameters. For information on passing parameters, see
using cfinvoke" on page
•
If the component method returns a result, the name of the variable that will contain the result,
in the
returnVariable
To invoke a component method using the cfinvoke tag:
Create the following component and save it as tellTime.cfc:
1
<cfcomponent>
<cffunction name="getLocalTime">
<cfoutput>#TimeFormat(now())#</cfoutput>
</cffunction>
</cfcomponent>
The example defines a component with one method,
time.
Create a ColdFusion page, with the following code and save it in the same directory as the
2
tellTime component:
<h3>Time Display Page</h3>
<b>Server's Local Time:</b>
<cfinvoke component="tellTime" method="getLocalTime"><br>
Using the
cfinvoke
creating a persistent CFC instance.
Invoking methods of a CFC instance
To invoke a component method of a CFC instance, use the
following:
•
The CFC instance name, enclosed in pound signs (#), in the
•
The method name, in the
•
Any parameters. For information on passing parameters, see
using cfinvoke" on page
•
If the component method returns a result, the name of the variable that will contain the result
in the
returnVariable
226
Chapter 11: Building and Using ColdFusion Components
tag to invoke CFC methods from within a CFC.
cfinvoke
cfinvoke
attribute
method
228.
attribute.
tag, the example invokes the
attribute
method
228.
attribute.
tag can invoke component methods without
tag and specify the following:
cfinvoke
attribute
component
"Passing parameters to methods
getLocalTime
component method without
getLocalTime
cfinvoke
component
"Passing parameters to methods
, that displays the current
tag and specify the
attribute
Need help?
Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?
Questions and answers