Jump to content

CFScript

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 64.61.91.178 (talk) at 22:20, 14 January 2013 (References). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

CFScript is an extension of CFML on the ColdFusion platform. CFScript resembles JavaScript. Some ColdFusion developers prefer it since it has less visual and typographical overhead than ordinary CFML; only the actual changes are represented in the code (whereas normal CFML would involve CFSET tags at every line).

Usage

All CFScript code must be contained within a CFScript tag pair, as follows:

<cfscript>
    xParam = 115;
    yParam = 200;
    color = 'FFCC99';
</cfscript>

While many ColdFusion tags have exact CFScript analogies, there are quite a few tags that do not. These include both complex tags that would be difficult to duplicate and simple tags that are easy to imitate (using ColdFusion UDF's):

Complex:

<cfquery>
<cffile>
<cfdirectory>

Simple:

<cfdump>
<cfthrow>

While there may not be direct substitutions for all tags, it is often still possible to achieve the results of a tag in script, but via a different syntax. For example this is how to get a query into a variable in CFSCRIPT without writing a UDF:

<cfscript>
  qGetData = new Query(); 
  qGetData .setDataSource('#APPLICATION.datasource#');
  qGetData .setSQL('SELECT column1, column2 FROM table WHERE 1'); 
  qDateResult = qGetData .Execute().getResult();
</cfscript>

Syntax

Since Coldfusion 8 cfscript has supported syntax abbreviations that are common in many other programming languages, such as "++", "<=" and "+=".[1]

References

Extending ColdFusion Pages with CFML Scripting - Adobe