Adobe ColdFusion 8

Invoking component methods transiently

In ColdFusion pages or components, the cfinvoke tag can invoke component methods without creating a persistent CFC instance.

To invoke a component method transiently, use the cfinvoke tag and specify the following:

  • The name or path of the component, in the component attribute.
  • The method name, in the method attribute.
  • Any parameters. For information on passing parameters, see Passing parameters to methods by using the cfinvoke tag.
  • If the component method returns a result, the name of the variable that contains the result, in the returnVariable attribute.
  1. Create the following component and save it as tellTime.cfc:
    <cfcomponent>
        <cffunction name="getLocalTime">
            <cfoutput>#TimeFormat(now())#</cfoutput>    
        </cffunction>
    </cfcomponent>
    

    The example defines a component with one method, getLocalTime, that displays the current time.

  2. Create a ColdFusion page, with the following code, and save it in the same directory as the tellTime component:
    <h3>Time Display Page</h3>
    <b>Server's Local Time:</b>
    <cfinvoke component="tellTime" method="getLocalTime">
    

    Using the cfinvoke tag, the example invokes the getLocalTime component method without creating a persistent CFC instance.