Introducing CFML

     

CFML is a tag-based programming language, similar to HTML in format. CFML consists of about 100 tags, enclosed in angle brackets like HTML tags.

All CFML tag names start with cf. Not all ColdFusion language elements are tags, however. For instance, there are built-in functions such as iif() .

The iif() Function

The iif() function evaluates an expression ( condition in the following code). Depending on whether the expression is true or false, iif() dynamically evaluates one of two string expressions ( string_expression1 and string_expression2 ) and returns the result.

It's equivalent to:

 <cffunction>     <cfif condition>        <cfset result = Evaluate(string_expression1)>     <cfelse>         <cfset result = Evaluate(string_expression2)>     </cfif>     <cfreturn result> <cffunction> 


In most cases, when you apply a tag, you use a start tag and an end tag. The end tag has the same name as the start tag but is preceded by a forward slash (/).

For example:

 <cfoutput>  Hello  </cfoutput> 

Table 33.1 lists some commonly used ColdFusion tags. The rest of this chapter illustrates the use of these tags.

Table 33.1. Some Commonly Used ColdFusion Tags

Tag

Purpose

cfapplication

Defines various client behaviors associated with an application, such as whether the client can log information in a cookie, and whether the client session will time out.

cfargument

Within a function, defines a parameter (data passed to the function).

cfbreak

See cfloop .

cfcatch

See cftry .

cfcomponent

Creates a ColdFusion component (CFC), an object encapsulating procedures (functions, referred to as methods ), and data ( variables and parameters).

cfdirectory

Returns a list of files in a directory. Can also create, delete, and rename directories.

cfdump

Displays the contents of variables, objects, components , user -defined functions, and other elements. Useful for debugging.

cfelse

See cfif .

cffile

Performs operations such as reading, writing, and appending to files on the ColdFusion server.

cffunction

Defines a ColdFusion function (an object encapsulating a procedure).

cfhttp

Generates an HTTP request and handles the response from the server.

cfif

Executes enclosed code if a condition is true. Can be used with cfelse to define an action to perform if the condition is not true.

cfimport

Imports all ColdFusion pages in a directory into the calling page as a custom tag library.

cfinclude

Adds the contents of the included ColdFusion page to the page containing the cfinclude tag, as if the code on the included page were part of the page containing the cfinclude tag.

cfinvoke or a Web service.

Invokes (runs or executes) either a function (method) in a component.

cflock

Locks ( prevents simultaneous access to) a single section of code, two or more different sections of code, or a scope. Locks prevent simultaneous change of the same variable to two different values.

cfloop

Loops through the tag body zero or more times, based on a condition specified by the tag attributes. The cfbreak tag exits a cfloop tag.

cfmail

Sends SMTP mail messages with application variables, query results, or server files. (See also cfpop , for getting mail.)

cfmodule

Invokes a custom tag, providing a workaround for custom tag name conflicts.

cfobject

Loads an object into a variable. Can load a CFC or an object written in other programming languages, including COM (Component Object Model) components, Java objects such as Enterprise JavaBeans, or CORBA (Common Object Request Broker Architecture) objects.

cfoutput

Displays output that can contain the results of processing ColdFusion functions, variables, and expressions.

cfparam

Creates a variable if it doesn't already exist. Optionally, sets the variable to a default value. If the variable already exists, cfparam does not change its value.

cfpop

Retrieves and/or deletes email messages from a POP mail server.

cfquery

Establishes a connection to a database (if a connection does not exist), executes a query operation such as insert, retrieve, update, or delete, and returns results.

cfreturn

Returns a result from a function.

cfset

Sets or resets the value of a ColdFusion variable. If the variable doesn't already exist, cfset creates the variable and sets the value. If the variable does exist, cfset sets the value.

cftry

Used with one or more cfcatch tags to catch and process exceptions (events such as failed database operations that disrupt normal program flow).




Using Macromedia Studio MX 2004
Special Edition Using Macromedia Studio MX 2004
ISBN: 0789730421
EAN: 2147483647
Year: N/A
Pages: 339

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