Understanding the Language


The CFML language consists of about 100 tags, each enclosed in angle brackets like HTML tags, and all the CFML tag names start with CF. Each of these tags indicates what function the ColdFusion server should perform on the content that falls between the tags.

ColdFusion also contains quite a few functions that enable you to perform operational comparisons, check for certain conditions, and even perform simple file-based operations. These functions are also invoked by a set of tags and many of them are capable of accepting arguments.

Table 18.1 lists some commonly used ColdFusion tags and functions, and later in the chapter we'll take a look at how they operate.

Table 18.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.

CFCALENDAR

New in ColdFusion MX 7, this tag allows you to invoke interactive Flash-based calendars.

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.

CFDOCUMENT

New in ColdFusion MX 7, this tag creates a PDF or FlashPaper output of the content that falls between the tags.

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.

CFFORM

Creates an instance of a form that can be validated on the server side.

CFFORMITEM

New for ColdFusion MX 7, this tag enables you to create a container that specifies controls for multiple forms.

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

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

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.

CFNTAUTHENTICATE

New for ColdFusion MX 7, this tag enables you to authenticate user credentials against a Windows NT domain.

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.

CFTIMER

New in ColdFusion MX 7, this function displays a timer indicating how long it took a section of CFML code to execute.

CFTRY

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


Many of ColdFusion's functions are able to accept arguments that further refine how the function behaves. When learning the tags, pay close attention to what types of data the functions can accept.

In addition to tags and functions, ColdFusion enables you to create variables. Think of a variable as a data container that contains a unique name. Using CFML, you can not only name the container, but fill it with data as well. For instance, take a look at the following code:

<CFSET myName = "Sean">


This code defines a variable called "myName". It also specifies that the initial value of the variable is Sean. Because the data being inserted into the variable is surrounded by quotes, ColdFusion recognizes it as a stringor data that can contain both numeric and alphanumeric data. After the variable is established, you can display it by using the cfoutput tag like this:

<CFOUTPUT>#myName#</CFOUTPUT>


Note

When calling variables, surround the variable name with pound signs so that the ColdFusion engine knows that it shouldn't simply output the text between the tags.


Tip

When creating variables in ColdFusion, remember these tips:

  • Variable names must begin with a letter, underscore, or Unicode currency symbol.

    You cannot begin variable names with a number.

  • Variable names cannot contain spaces.

  • Variable names are not case sensitive.


Now that you've created your variable, you aren't limited to simply displaying the variable. Depending on the type of data stored in the variable, you can use it in calculations or even run comparisons against it.

When you create your variable, you also need to consider its scope. The scope of a variable defines how long the variable should exist and what portions of the page code can use the variable. Because it's important to know when it's okay to use your variable, it's important to define the scope of each variable. ColdFusion has a variety of predefined scope types, so the easiest way to define the scope of a new variable is simply to assign it to one of these types.

You can specify a scope explicitly by putting it before the variable and separating the two with a period. For instance, if you wanted to define the myName variable scope as "session" so that it lasted for the duration of the user's browser session, you would define it by typing

<CFSET Session.myName = "Sean">


This would define the variable, set the initial value, and define the scope of the variable as existing until the session expires.

Table 18.2 lists some commonly used variable types that are available in CFML.

Table 18.2. Commonly Used Variable Types Available in CFML

Data Type

Data Stored

String

Text data wrapped in quotes such as "Hello World" or "Sean".

Number

Numeric values. Unlike other languages, CFML does not require that you specify whether or not the number contains decimal points.

Boolean Value

"Yes", "No", "True", "False", 0, or 1.

Date/Time

Date and time values in formats such as 08/05/2005, 2005-08-05, or 08/05/2005 02:30:00 pm.




Special Edition Using Macromedia Studio 8
Special Edition Using Macromedia Studio 8
ISBN: 0789733854
EAN: 2147483647
Year: 2003
Pages: 337

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