CFFUNCTION  
Description

Defines functionality that you build in CFML.

 
Category

Extensibility tags

 
Syntax
    <cffunction
   name = "methodName"
   returnType = "dataType"
   roles = "securityRoles"
   access = "methodAccess"
   output = "yes" or "no" >

  
 
See also

cfargument, cfcomponent, cfinvoke, cfinvokeargument, cfobject, cfproperty, cfreturn

 
Usage

Components that are stored in the same directory are members of a component package.

Within a cffunction tag, if you specify the roles attribute, the method executes only if a user is logged in and belongs to one of the specified roles.

For more information, see the "Building and Using ColdFusion Components" chapter in Developing ColdFusion MX Applications with CFML.

The following example shows a typical use of this tag:

<cffunction
   name="getEmployees" 
   access="remote" 
   returnType="query" 
   hint="This query returns all records in the employee database. It can
drill-down or narrow the search, based on optional input parameters.">
 
Example
<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>
NAME  
  Required
 

A string; a component method that is used within the cfcomponent tag.

RETURNTYPE  
  Required for a web service; Optional, otherwise.
 
Default value: " any"

String; a type name; data type of the function return value.

  • any
  • array
  • binary
  • boolean
  • date
  • guid
  • numeric
  • query
  • string
  • struct
  • uuid
  • variableName
  • void (this option does not return a value)
  • a return type

If the value is not a recognized type, ColdFusion processes it as a component name.

ROLES  
  Optional
 
Default value: """ (empty)"

This attribute is used only for a component.

A comma-delimited list of ColdFusion security roles that can invoke the method. If this attribute is omitted, all roles can invoke the method.

ACCESS  
  Optional
 
Default value: "public"

This attribute is used only for a component.

The client security context from which the method can be invoked:

  • private: available only to the component that declares the method
  • package: available only to the component that declares the method or to another component in the package
  • public: available to a locally executing page or component method
  • remote: available to a locally or remotely executing page or component method, or a remote client through a URL, Flash, or a web service. To publish the function as a web service, this option is required.
OUTPUT  
  Optional
 
Default value: "Function is processed as standard CFML"

This attribute is used only for a component.

  • yes: the function is processed as if it were within a cfoutput tag
  • no: the function is processed as if it were within a cfsilent tag