cfscript


<cfscript>

Although ColdFusion Markup Language (CFML) is a complete language for building ColdFusion templates, you can use an alternative syntax known as ColdFusion Script (<cfscript>). A ColdFusion Script block is surrounded with opening and closing <cfscript> tags as follows:

 <cfscript> // scripting will go here // (note the different comment syntax) </cfscript> 

Benefits of <cfscript>

Scripting offers a few advantages over using CFML tags. First, scripting is more concise for some operations. A <cfscript> block begins and ends with a CFML tag, but no tags are needed within the block itself. Second, scripting resembles JavaScript and could be easier for developers familiar with traditional development languages to relate to. Finally, scripting provides an easy way to work with the parameters and methods of external objects (including Java, COM, or CORBA).

Drawbacks of <cfscript>

Although scripting is well suited for many tasks, it doesn't include all of ColdFusion functionality. Some of the strongest featuressuch as query services, HTTP, FTP, email, and LDAPare not available within a <cfscript> block. In fact, only the following features are available to the ColdFusion scriptwriter:

  • Variable assignment

  • Looping

  • Conditional statements

  • Object invocation (including ColdFusion Components)

  • Try/catch handling

  • User-defined function creation

Anything beyond this list requires the use of ColdFusion's tag-based syntax.

NOTE

Although many of ColdFusion's services are not available through scripting, you can work with the data that these services return. For example, a query may return ten rows of data. Although the query couldn't be launched through scripting, the ten rows of data are exposed with no contingencies.


The biggest limitation of <cfscript> is that it cannot access CFML tags, so no <cfquery> or <cfmail> tags are available. However, <cfscript> code can access any functions and expressions, including user-defined functions.



Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net