Jump to content

ColdFusion Markup Language: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Disambig links to dab page variable and general clean-up using AWB
Line 124: Line 124:
CFCs are created using four tags, saved as.CFC files, and invoked using the <cfinvoke> tag.<ref>Ben Forta, "Using ColdFusion components"[http://www.adobe.com/devnet/coldfusion/articles/intro_cfcs.html]</ref>
CFCs are created using four tags, saved as.CFC files, and invoked using the <cfinvoke> tag.<ref>Ben Forta, "Using ColdFusion components"[http://www.adobe.com/devnet/coldfusion/articles/intro_cfcs.html]</ref>


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.<source lang="cfm">
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.
<source lang="cfm">
<!--- temperature.cfc --->
<!--- temperature.cfc --->
<cfcomponent>
<cfcomponent>

Revision as of 15:47, 19 May 2009

Template:Mergesection

Cold Fusion Markup Language (CFML)
Paradigmimperative, object-oriented
Designed byJeremy Allaire
DeveloperAdobe Systems, Railo, New Atlanta
First appeared1995
OSWindows, Linux, UNIX, Macintosh
LicenseDepends on the implementation
WebsiteAdobe ColdFusion, Railo, BlueDragon
Major implementations
Adobe ColdFusion, Railo, BlueDragon

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.

Synopsis

CFML augments standard HTML files with database commands, conditional operators, high-level formatting functions, and other elements to produce web applications.[1]

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.[2]

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.[3]

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.

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

Sometimes, although the tag can have a body, you find that you do not need to put anything in it because the attributes specify all the required information. In these cases (as with all HTML), you can choose to omit the end tag (and hence, the body) and just put a forward slash character before the closing (>) character, as in the following example:[4]

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

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 used 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.[5]

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.

  • Array functions[6] (ArrayNew, ArraySort, ArrayPrepend, ArrayAppend, ArrayDeleteAt...)
  • Conversion functions[7] (URLEncodedFormat, ToString...)
  • Date and time functions[8] (LsDateFormat, LsTimeFormat, DateAdd, DateDiff...)
  • Decision functions[9] (IsDefined, IIF...)
  • Display and formatting functions[10] (CJustify, NumberFormat...)
  • Dynamic evaluation functions[11] (DE, Evaluate...)
  • Extensibility functions[12] (CreateObject, ToScript...)
  • Image functions[13] (ImageRotate, ImageAddBorder...)
  • International functions[14] (SetLocale, GetTimeZoneInfo...)
  • List functions[15] (FindOneOf, ListSetAt...)
  • Mathematical functions[16] (Randomize, Sqr...)
  • Other functions[17] (WriteOutput, GetBaseTemplatePath...)
  • Query functions[18] (QueryAddColumn, QuerySetCell...)
  • Security functions[19] (Encrypt, Decrypt...)
  • String functions[20] (Reverse, HTMLCodeFormat...)
  • Structure functions[21] (StructKeyExists, StructDelete...)
  • System functions[22] (GetTickCount, GetTempFile...)
  • XML functions[23] (XMLParse, GetSOAPResponse...)

ColdFusion Components (CFCs)

CFCs 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.[24]

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. ^ ColdFusion Markup Language[1]
  2. ^ Michael Smith. "What is ColdFusion?" [2]
  3. ^ Tags. [3]
  4. ^ Tag syntax[4]
  5. ^ Tags by function. [5]
  6. ^ Array functions[6]
  7. ^ Conversion functions[7]
  8. ^ Date and time functions[8]
  9. ^ Decision functions[9]
  10. ^ Display and formmatting functions[10]
  11. ^ Dynamic evaluation functions[11]
  12. ^ Extensibility functions[12]
  13. ^ Image functions[13]
  14. ^ International functions[14]
  15. ^ List functions[15]
  16. ^ Mathematical functions[16]
  17. ^ Other functions[17]
  18. ^ Query functions[18]
  19. ^ Security functions[19]
  20. ^ String functions[20]
  21. ^ Structure functions[21]
  22. ^ System functions[22]
  23. ^ XML functions[23]
  24. ^ Ben Forta, "Using ColdFusion components"[24]