In the component method definition, you use the cfreturn tag to return the results to the client as variable data. For example, the following getLocalTime2
component method returns the local time as a variable to the ColdFusion page or other client that invokes the method:
<cfcomponent> <cffunction name="getLocalTime"> <cfreturn TimeFormat(now())> </cffunction> </cfcomponent>
The ColdFusion page or other client, such as a Flash application, that receives the result then uses the variable data as appropriate.
Note: If a CFC is invoked using a URL or by submitting a form, ColdFusion MX returns the variable as a WDDX packet. A CFC that is invoked by Flash Remoting MX, or any other instance of a CFC, must not return the This scope.
You can return values of all data types, including strings, integers, arrays, structures, and instances of CFCs. The cfreturn
tag returns a single variable, as does the return
CFScript statement. Therefore, if you want to return more than one result value at a time, use a structure. If you do not want to display output in a method, use output=
"false
" in the cffunction tag.
For more information on using the cfreturn
tag, see CFML Reference.