cffunction

Defines a function that you can call in CFML. Required to
defined CFML component methods.

 <cffunction name="">

 public boolean function myFunction(required any myArgument) { }

cffunction Attribute Reference

name
Required

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

returntype
Default: any

String; a type name; data type of the function return value
Required for a web service; Optional, otherwise. Values:
  • any
  • array
  • binary
  • boolean
  • date
  • guid
  • numeric
  • query
  • string
  • struct
  • UUID
  • variablename
  • void
  • xml
  • (component name)

roles

A comma-delimited list of CFML security roles that
can invoke the method. Only users who are logged in with
the specified roles can execute the function. If this
attribute is omitted, all users can invoke the method

access
Default: public

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

private: available only to the component that declares the
method and any components that extend the component in
which it is defined
package: available only to the component that declares the
method, components that extend the component, or any
other components 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. Values:
  • private
  • package
  • public
  • remote

output

Specifies under which conditions the function can generate
HTML output.

displayname

Meaningful only for CFC method parameters. A value to be
displayed in parentheses following the function name when
using introspection to show information about the CFC

hint

Meaningful only for CFC method parameters. Text to be
displayed when using introspection to show information
about the CFC. The hint attribute value follows the syntax
line in the function description

description

Supplies a short text description of the function.

returnformat

The format in which to return values to a remote caller. Values:
  • JSON
  • plain
  • WDDX

securejson

A Boolean value that specifies whether to add a security prefix in front of any value that the function returns in JSON-format in response to a remote call.

verifyclient

A Boolean value that specifies whether to require remote function calls to include an encrypted security token. For use with ColdFusion AJAX applications only.

restPath

Specify to use a sub- resource path for the CFC. The path is case-sensitive. Also, it is preferable to avoid special characters when you specify the path. You can include regular expressions in the path. For details of the expressions that you can specify, see the attribute restPath in cfcomponent.

httpMethod

The HTTP method to use, must be one of the following:

GET: Requests information from the server. Any data that the server requires to identify the requested information must be in the URL or in cfhttp type="URL" tag.

POST: Sends information to the server for processing. Requires one or more cfhttpparam tags. Often used for submitting form-like data.

PUT: Requests the server to store the message body at the specified URL. Use this method to send files to the server.

DELETE: Requests the server to delete the specified URL.

HEAD: Identical to the GET method, but the server does not send a message body in the response. Use this method for testing hypertext links for validity and accessibility, determining the type or modification time of a document, or determining the type of server. If you have not specified HEAD, by default, GET method is called. However, message body is not sent in the response.

OPTIONS: A request for information about the communication options available for the server or the specified URL. This method enables the ColdFusion application to determine the options and requirements associated with a URL, or the capabilities of a server, without requesting any additional activity by the server. If you have not specified OPTIONS, then ColdFusion sends a response.
Overrides the value that you specify at component level. Values:
  • get
  • post
  • put
  • delete
  • head
  • options

produces

Comma-separated list of acceptable MIME types. Used to specify the MIME media type of representation a resource can produce, for example, {{produces="text/plain,text/html"}} If a resource can produce more than one MIME media type, the function chosen corresponds to the most acceptable media type as declared by the client. If no value is specified, / is taken by default, which means, all MIME types are consumed. Overrides the value that you specify at the component level.

Note
If MIME type is a wildcard, the results include any value. For example, if you a make a http call with produces as '*/xml' and follow it up with a second http call with produces as '*/json', the results in the second http call might include the first call result as well.

consumes

Comma-separated list of acceptable MIME types, for example consumes="text/plain,text/html".Used to specify which MIME media types of representation a resource can accept, or consume, from the client. This attribute overrides the same attribute at the component level.
If no value is specified, / is taken by default, which means, all MIME types are consumed. Adobe recommends that you avoid conflict scenarios while specifying the attributes produces and consumes. For example, avoid situations such as the following: In function 1, you specify produces as text/xml and consumes as text/ and in function 2, produces as text/ and consumes as text/xml. Here, both the functions are valid for the request with accept = text/xml and consumes as text/xml.

Examples sample code using the cffunction tag


Script Syntax

public boolean function myFunction(required any myArgument) { 
  // Some function bits 
 return true; 
 }

Tag Syntax

<cffunction access="public" returntype="boolean" name="myFunction"> 
 <cfargument required="true" type="any" name="myArgument"> 
 <!--- Some function bits ---> 
 <cfreturn true> 
 </cffunction>

Fork me on GitHub