ColdFusion Markup Language

Article on other languages:

del.icio.us del.icio.us
Digg Digg
Furl Furl
Reddit Reddit
Rojo Rojo
Add to OnlyWire
Adobe Systems Cold Fusion Markup Language (CFML)
Paradigm imperative, object-oriented
Appeared in 1995
Designed by Jeremy Allaire
Developer Adobe
Latest release 8/ July 30, 2007
Major implementations Adobe ColdFusion
OS Windows, Linux, UNIX, Macintosh
License Proprietary
Website Adobe ColdFusion

ColdFusion Markup Language, more commonly known as CFML, is the scripting language used by Adobe ColdFusion, BlueDragon and Railo, as well as other CFML server engines.

Contents

Synopsis

CFML is a tag-based versatile scripting language that is self-contained and easy-to-learn. It promotes rapid web application development. ColdFusion code is short and concise. It is easy to understand exactly what the code does, even without programming knowledge.[1]

CFML enhances standard HTML files with database commands, conditional operators, high-level formatting functions, and other elements to rapidly produce easy-to-maintain web applications.[2]

The pages in a ColdFusion application include the server-side CFML tags in addition to HTML (XHTML) tags. When a browser requests a page in a ColdFusion application, it is automatically pre-processed by the ColdFusion Application Server.[3]

ColdFusion tags tell the ColdFusion server that it must process the tagged information. The ColdFusion server only processes ColdFusion tag contents; it returns text outside of ColdFusion tags to the web server unchanged.[4]

Syntax

ColdFusion tags have the same format as HTML tags. They are enclosed in angle brackets (< and >) and can have zero or more named attributes. Many ColdFusion tags have bodies; that is, they have beginning and end tags with text to be processed between them. For example:

<cfoutput>
   #value# Bob!
</cfoutput>

Other tags, such as cfset and cfftp, never have bodies; all the required information goes between the beginning (<) character and the ending (>) character, as in the example below. If it is legal for tags not to have a body, it is syntactically acceptable to leave them unclosed. However, the self-closing variant is recommended as it complies with XHTML standards.

 
<cfset value = "Hello">
<cfset value = "Hello" />

Sometimes, although the tag can have a body, you do not need to put anything in it because the attributes specify all the required information. You can omit the end tag and put a forward slash character before the closing (>) character, as in the following example:[5]

<cfexecute name="C:\winNT\System32\netstat.exe" arguments = "-e" outputfile="C:\Temp\out.txt" timeout = "1" />

CFML is generally considered a dynamic language. Various tags offer the ability to type-check input parameters (e.g. cffunction, cfparam, cfqueryparam) if the programmer declares their type specifically. This functionality is put into very good use with cfqueryparam to secure web applications and databases from hackers and malicious web requests.

Built-in tags

Over 80 built-in tags make up the heart of ColdFusion. The following lists CFML tags by their function or purpose.[6]

Custom tags

CFML allows language extensions in the form of custom tags. In other words, CFML allows tags that are not built-in ColdFusion tags. Custom tags are normal files which are intended to be invoked as tags, although it is possible to treat a template as both a custom tag and a regular template. Custom tags written in CFML may be prefixed with cf_, although there are other ways to invoke them.

If a template is invoked as a custom tag, the attributes used to invoke that tag are available in a special structure attributes and the variables on the calling page are accessible via the caller struct. For example, if writing an add tag which takes two attributes and adds them together, the sum.cfm page would look like this:

<cfset caller.sum = attributes.first + attributes.second / >

Assuming the template and tag are in the same directory, the tag can be invoked thus:

<cf_sum first="1" second="2">

CFX tags are custom tags which are developed using Java language or C++, and are prefixed with cfx_ just like cf_. Tags are added to the ColdFusion runtime environment using the ColdFusion administrator, where JAR or DLL files are registered as custom tags.

JSP tags can also be included in CFML pages using the <cfimport> tag.

Functions

ColdFusion Markup Language includes a set of functions that you use to perform logical and arithmetic operations and manipulate data.[7]

    • Array functions (ArrayNew,[8] ArraySort,[9] ArrayPrepend,[10] ArrayAppend,[11] ArrayDeleteAt[12]...)
    • Conversion functions (URLEncodedFormat,[13] ToString[14]...)
    • Date and time functions (LsDateFormat,[15] LsTimeFormat,[16] DateAdd,[17] DateDiff[18]...)
    • Decision functions (IsDefined,[19] IIF[20]...)
    • Display and formatting functions (CJustify,[21] NumberFormat[22]...)
    • Dynamic evaluation functions (DE,[23] Evaluate[24]...)
    • Extensibility functions (CreateObject,[25] ToScript[26]...)
    • Image functions (ImageRotate,[27] ImageAddBorder[28]...)
    • International functions (SetLocale,[29] GetTimeZoneInfo[30]...)
    • List functions (FindOneOf,[31] ListSetAt[32]...)
    • Mathematical functions (Randomize,[33] Sqr[34]...)
    • Other functions (WriteOutput,[35] GetBaseTemplatePath[36]...)
    • Query functions (QueryAddColumn,[37] QuerySetCell[38]...)
    • Security functions (Encrypt,[39] Decrypt[40]...)
    • String functions (Reverse,[41] HTMLCodeFormat[42]...)
    • Structure functions (StructKeyExists,[43] StructDelete[44]...)
    • System functions (GetTickCount,[45] GetTempFile[46]...)
    • XML functions (XMLParse,[47] GetSOAPResponse[48]...)

ColdFusion Components (CFCs)

CFCs provide the power of objects with the simplicity of CFML. They provide some (not all) of the typical features and functionality that are provided by object-oriented (OOP) languages. To create a CFC:

Create a file with a.CFC extension (this distinguishes CFCs from ColdFusion templates, which have a.CFM extension).
Use four tags to create the components, define their functions and arguments, and return a value.
<cfcomponent>: Defines a CFC
<cffunction>: Defines the functions (methods) within a CFC
<cfargument>: Defines the arguments (parameters) that a function accepts
<cfreturn>: Returns a value or result from a function

CFCs are plain CFML. Within a CFC you can use any tag, function, custom tag, component, and more. After creating your CFC, save it with.cfc extension.

To use your CFC, use <cfinvoke> tag to call your component methods from a.cfm file. <cfinvoke> takes the name of the component (minus the.cfc extension) and the method to execute. To access any returned data, the RETURNVARIABLE attribute provides the name of a variable to contain whatever the function returns. CFCs are created using four tags, saved as.CFC files, and invoked using the <cfinvoke> tag.[49]

In the example below, component temperature.cfc has a method FtoC which converts temperature from Fahrenheit to Celsius. The test.cfm template invokes the method and converts 212 degrees Fahrenheit and outputs the result.

<!--- temperature.cfc --->
<cfcomponent>
  <cffunction name="FtoC" access="public" returntype="numeric">
    <cfargument name="fahrenheit" required="yes" type="numeric" />
    <cfset answer= (fahrenheit - 32)*100/180 />
    <cfreturn answer />
  </cffunction>
</cfcomponent>
<!--- test.cfm --->
<cfset fDegrees = 212 />
<cfinvoke component="temperature" method="FtoC" returnvariable="result">
  <cfinvokeargument name="fahrenheit" value="#fDegrees#" />
</cfinvoke>
<cfoutput>#fDegrees#<sup>o</sup>F = #result#<sup>o</sup>C</cfoutput> <br />

References

  1. ^ Tom Muck. "Switching from PHP to ColdFusion" [1]
  2. ^ ColdFusion Markup Language[2]
  3. ^ Michael Smith. "What is ColdFusion?" [3]
  4. ^ Tags. [4]
  5. ^ Tag syntax[5]
  6. ^ Tags by function. [6]
  7. ^ Functions by Category[7]
  8. ^ ArrayNew[8]
  9. ^ ArraySort[9]
  10. ^ ArrayAPrepend[10]
  11. ^ ArrayAppend[11]
  12. ^ ArrayDeleteAt[12]
  13. ^ URLEncodedFormat[13]
  14. ^ ToString[14]
  15. ^ LsDateFormat[15]
  16. ^ LsTimeFormat[16]
  17. ^ DateAdd[17]
  18. ^ DateDiff[18]
  19. ^ IsDefined[19]
  20. ^ IIF[20]
  21. ^ CJustify[21]
  22. ^ NumberFormat[22]
  23. ^ DE[23]
  24. ^ Evaluate[24]
  25. ^ CreateObject[25]
  26. ^ ToScript[26]
  27. ^ ImageRotate[27]
  28. ^ ImageAddBorder[28]
  29. ^ SetLocale[29]
  30. ^ GetTimeZoneInfo[30]
  31. ^ FindOneOf[31]
  32. ^ ListSetAt[32]
  33. ^ Randomize[33]
  34. ^ Sqr[34]
  35. ^ WriteOutput[35]
  36. ^ GetBaseTemplatePath[36]
  37. ^ QueryAddColumn[37]
  38. ^ QuerySetCell[38]
  39. ^ Encrypt[39]
  40. ^ Decrypt[40]
  41. ^ Reverse[41]
  42. ^ HTMLCodeFormat[42]
  43. ^ StructKeyExists[43]
  44. ^ StructDelete[44]
  45. ^ GetTickCount[45]
  46. ^ GetTempFile[46]
  47. ^ XMLParse[47]
  48. ^ GetSOAPResponse[48]
  49. ^ Ben Forta, "Using ColdFusion components"[49]

External links

This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.


Giant Panda

Mercedes Car
James Bond Guide
This site monitored by SitePinger.net