Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 197

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Invoking component methods transiently
In ColdFusion pages or components, the
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
tag" on page 196.
• If the component method returns a result, the name of the variable that contains the result, in the
attribute.
The following procedure creates an application that displays the local time.
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,
Create a ColdFusion page, with the following code, and save it in the same directory as the tellTime component:
2
<h3>Time Display Page</h3>
<b>Server's Local Time:</b>
<cfinvoke component="tellTime" method="getLocalTime">
Using the
tag, the example invokes the
cfinvoke
CFC instance.
Using the cfinvoke tag within the CFC definition
You can use the
tag to invoke a component method within the component definition; for example, to call a
cfinvoke
utility method that provides a service to other methods in the component. To use the
do not create an instance or specify the component name in the
<cfcomponent>
<cffunction name="servicemethod" access="public">
<cfoutput>At your service...<br></cfoutput>
</cffunction>
<cffunction name="mymethod" access="public">
<cfoutput>We're in mymethod.<br></cfoutput>
<!--- Invoke a method in this CFC. --->
<cfinvoke method="servicemethod">
</cffunction>
</cfcomponent>
Note: When you invoke a method from within the component definition in which you define the method, do not use the
This scope, because this resets the access privileges.
tag can invoke component methods without creating a persistent
cfinvoke
cfinvoke
component
attribute.
method
getLocalTime
getLocalTime
Last updated 1/20/2012
tag and specify the following:
attribute.
"Passing parameters to methods by using the cfinvoke
, that displays the current time.
component method without creating a persistent
cfinvoke
tag, as the following example shows:
cfinvoke
192
returnVariable
tag in this instance,

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents