User Guide

Table Of Contents
Passing parameters to methods 225
Passing parameters to methods
This section describes how to pass parameters to a method in a CFC, including:
Passing parameters to methods using the cfinvoke tag
Passing parameters in direct method invocations
Passing parameters in a URL
Passing parameters to methods using the cfinvoke tag
When you use the
cfinvoke tag, ColdFusion MX provides several methods for passing
parameters to CFC methods:
As cfinvoke tag attributes, in name="value" format
In the cfinvoke tag argumentcollection attribute
In the cfinvoke tag body, using the cfinvokeargument tag
You can use any combination of these methods in a single invocation. If you use the same name in
two or three of these methods, ColdFusion uses the value based on the following order of
precedence:
1.
cfinvokeargument tags
2.
cfinvoke attribute name-value pairs
3.
argumentcollection arguments
Passing parameters using attribute format
You can pass parameters in the
cfinvoke tag as tag attribute name-value pairs, as the following
example shows:
<cfinvoke component="authQuery" method="getAuthSecure"
lastName="#session.username#" password="#url.password#">
In the example, the parameters are passed as the lastName and password attributes.
Note: The cfinvoke tag attribute names are reserved and cannot be used for parameter names. The
reserved attribute names are:
component, method, argumentCollection, and returnVariable. For more
information, see CFML Reference.
Passing parameters in the argumentCollection attribute
If you save attributes to a structure, you can pass the structure directly using the
cfinvoke tags
argumentCollection attribute. This technique is useful if an existing structure or scope (such as
the Forms scope) contains values that you want to pass to a CFC as parameters, and for using
conditional or looping code to create parameters.
When you pass an argumentCollection structure, each structure key is the name of a parameter
inside the structure.