<cffunction>
Defines a function call
This tag must have a body.
This tag is also supported within <cfscript>
<cffunction
name=string
returntype=string
bufferoutput=boolean
roles=string
access=string
output=boolean
displayname=string
hint=string
abstract=boolean
description=string
returnformat=string
securejson=boolean
verifyclient=boolean
localmode=string
cachedwithin=object
modifier=string
consumes=string
produces=string
httpmethod=GET|PUT|POST|DELETE
restpath=string
><!--- body ---></cffunction>
Attribute | Description |
---|---|
name
string, required
|
A string; a component method that is used within the cfcomponent tag. |
returntype
string, optional
|
String; a type name; data type of the function return value |
bufferoutput
boolean, optional
|
This attribute is only used when output of the function is set to false. If this attribute is set to true (default) the output written to the body of the function is buffered and in case of an exception also outputted. If set to false the content to body is ignored and not disabled when a failure in the body of the tag occur. |
roles
string, optional
|
This attribute is used only for a component. If this attribute is omitted, all roles can invoke the method. |
access
string, optional
|
This attribute is used only within a component. The client security context from which the method can be invoked
|
output
boolean, optional
|
This attribute is used only for a component.
|
displayname
string, optional
|
Display Name of the Function |
hint
string, optional
|
Hint of the Function |
abstract
boolean, optional
|
is the function abstract or not, abstract functions are only allowed inside interface or component tags |
description
string, optional
|
Supplies a short text description of the function. |
returnformat
string, optional
|
The format in which to return values to a remote caller. Supported values are
|
securejson
boolean, optional
|
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
boolean, optional
|
A Boolean value that specifies whether to require remote function calls to include an encrypted security token. For use with AJAX applications only. |
localmode
string, optional
|
Defines how the local scope of this function is invoked when a variable with no scope definition is used. Accepted values include:
|
cachedwithin
object, optional
|
possible values are:
To use cached data, the function must be called with the exact same arguments (part of the cache key is a hash of the arguments) |
modifier
string, optional
|
Use modifier to denote a function as abstract, static or final.
|
consumes
string, optional
|
A comma-separated list of acceptable MIME types that the function can accept or consume. If no value is specified, all MIME types are consumed by default. Use this attribute to control the types of content the function can handle. This attribute overrides the |
produces
string, optional
|
A comma-separated list of MIME types that the function can produce. The function will respond with the most acceptable media type as declared by the client. This attribute overrides the |
httpmethod
string, optional
|
Specifies the HTTP method to use when calling the function as part of a RESTful service. Accepted values include:
If not specified, the |
restpath
string, optional
|
Defines a sub-resource path for the function when used as part of a RESTful web service. The path is case-sensitive and should avoid special characters. Regular expressions can be included in the path. |
Examples
Simple Example with tag format
<cffunction access="private" name="add">
<cfargument name="arg1" type="Numeric" required />
<cfargument name="arg2" type="Numeric" required />
<cfreturn arg1 + arg2 />
</cffunction>
<cfdump var="Define function Using tag.It returns :#add(4,2)#" />
Simple Example with script format
writeDump("Define function using cfscript. It returns: "&add(2,3));
public function add(required numeric arg1,required numeric arg2){
return arg1+arg2;
}
See also
- Components (CFCs)
- Core CFML Language
- Static
- IsClosure()
- ValueRef()
- <cfargument>
- <cfcomponent>
- <cfreturn>
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)