View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cfreturn PreviousNext

cfreturn

Returns result values from a component method. Contains an expression returned as result of the function.

An expression; the result of the function from which this tag is called.

Extensibility tags

<cfreturn 
expr>

cfargument, cfcomponent, cffunction, cfinvoke, cfinvokeargument, cfobject, cfproperty

ColdFusion MX: Added this tag.

Attribute

Req/Opt

Default

Description

expr

Required

 

Function result; value of any type

This tag is equivalent to a return statement within a cfscript tag. It accepts one return variable argument. To return more than one value, populate a structure with name-value-pairs, and return the structure with this tag.

To access the result value from this tag, you use the variable scope that is the value of the cfinvoke tag returnVariable attribute.

For example code, see Building and Using ColdFusion Components in Developing ColdFusion MX Applications.

<cfcomponent>
   <cffunction name="getEmp">
       <cfquery name="empQuery" datasource="ExampleApps" >
          SELECT FIRSTNAME, LASTNAME, EMAIL
          FROM tblEmployees
       </cfquery>
       <cfreturn empQuery>
   </cffunction>
   <cffunction name="getDept">
      <cfquery name="deptQuery" datasource="ExampleApps" >
          SELECT *
          FROM tblDepartments
       </cfquery>
       <cfreturn deptQuery>
   </cffunction>
</cfcomponent>

Contents > CFML Reference > ColdFusion Tags > cfreturn PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


Hallow said on Nov 15, 2004 at 9:43 AM :
This doesn't appear to be documented anywhere, but in building custom tags, I've found that <cfreturn> can be used to break out of an execution mode (start primarily), without causing the tag processing to be stopped (like <cfexit> seems to do).
cfoli said on Mar 18, 2005 at 1:07 PM :
Does CFRETURN stop processing the code within a CFFUNCTION, or does it keep executing the code until </CFFUNCTION>, and then return the value specified ?

If it exits immediately, this means that we could have several CFRETURNs within a CFFUNCTION block ?

Ex:

<CFIF xxxxx>
[...code...]
<CFRETURN ErrorMsg1>
<CFELSEIF yyyy>
[...code...]
<CFRETURN ErrorMsg2>
<CFELSE>
[...code...]
<CFRETURN NoErrMsg>
</CFIF>
jrunrandy said on Mar 29, 2005 at 1:11 PM :
Yes, cfreturn stops processing at the point you call it.

Yes, you can have several cfreturns within a cffunction.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-a28.htm