Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define ColdFusion functions with the access="remote" attribute using scripting?

Tags:

coldfusion

The goal is to allow the definition of all functions of a .cfm or .cfc using scripting rather than CFML tags.

I would like to change this:

<cffunction name="foo" access="remote">
    <cfscript>
        ....
    </cfscript>
</cffunction>

Into something like this:

<cfscript>
    function remote foo() {
        ....
    }
</cfscript>

Or something else, as long as it can be done within opening and closing cfscript tags.

like image 357
Jean Vincent Avatar asked Apr 06 '11 09:04

Jean Vincent


People also ask

Can you use ColdFusion with CFScript?

Defining components and functions in CFScript. ColdFusion supports the syntax for defining CFCs, including interfaces, functions, properties, and parameters entirely in CFScript. Currently, however, only certain ColdFusion tags are supported as CFScript functions. This section describes the component definition syntax.

What is a function in ColdFusion?

ColdFusion Functions. A function is a self contained block of code that performs a given 'function', then returns a value. Often, a function will require that you pass it one or more arguments. The purpose of an argument is to provide the function with further info that it needs in order to process.

How to create functions using tags in ColdFusion?

I will now explain how to create functions using tags (you can also create functions in ColdFusion script). Function is declared with the usage of tag <cffunction>. What is inside this tag definition is part of function body and will be executed when the function is called.

How to access all the data in ColdFusion?

Before you can access all this data you need to connect to it. You need to tell ColdFusion server where to look for all this data. This is done through ColdFusion administrator.


2 Answers

Not possible in CF8, made possible in CF9:

access returnType function functionName(arg1Type arg1Name="defaultValue1" arg1Attribute="attributeValue...,arg2Type arg2Name="defaultValue2" arg2Attribute="attributeValue...,...) functionAttributeName="attributeValue" ... { body contents }

Defining components and functions in CFScript

So your function would look similar to:

<cfscript>
    remote function foo() {
        ...
    }
<cfscript>
like image 59
Lucas Avatar answered Oct 07 '22 05:10

Lucas


You could also do:

function foo() access="remote" returntype="JSON" {
like image 6
Sam Farmer Avatar answered Oct 07 '22 06:10

Sam Farmer