Working with ColdFusion pages

As discussed in Chapter 1, ColdFusion pages are plain text files that you use to create web applications. You can create your ColdFusion applications by writing all the code manually or by using wizards (provided with some editors) to generate the majority of the code for you.

You can use the following editors to create your ColdFusion pages:

The best choice for creating ColdFusion pages is Macromedia Dreamweaver MX. Dreamweaver MX includes many CFML features for building applications, such as rapid visual development, robust CFML editing, and integrated debugging. Dreamweaver MX also includes a copy of HomeSite+ for users who are familiar with developing their application code using ColdFusion Studio or HomeSite 5. HomeSite+ combines all the features of ColdFusion Studio and HomeSite 5, along with support for the latest ColdFusion MX tags.

Note:   This book shows how to create ColdFusion applications by writing your code manually. It does not address how to create ColdFusion pages by generating code with wizards. For information about using wizards to generate CFML code, see the product documentation for Dreamweaver MX and HomeSite+.

Creating a ColdFusion page

Creating a ColdFusion page involves using tags and functions. The best way to understand this process is to create a ColdFusion page.

In the following procedure, you will create a simple ColdFusion page by using HTML tags, one ColdFusion tag, and two ColdFusion functions. The following table briefly explains the ColdFusion tags and functions:
Element
Description
Now()
A function supported in CFML that you can use to retrieve information from your system.
You will use the Now() function in the following procedure to return the current date that is retrieved from your system.
DateFormat()
A function that instructs ColdFusion to format the date returned by the Now() function.
cfoutput
A ColdFusion tag that you use to return dynamic data (data retrieved from a database) to a web page.
You will use the cfoutput tag in the following procedure to display the current date retrieved from your system.

Note:   ColdFusion tags and functions are considered primary elements of CFML. You will learn more about these elements and others later in this book.

To create a ColdFusion page:

  1. Open your editor and create a blank file.
  2. Enter the following code on the page:
    <html>
    <head>
    <title>A ColdFusion Page</title>
    </head>
    <body>
    <strong>Hello world, this is a ColdFusion page.</strong> 
    <br>
    <cfoutput> Today's date is #DateFormat(Now())# </cfoutput>
    </body>
    </html>
    

Saving your ColdFusion page

In order for the ColdFusion server to process the page, you must save the ColdFusion page on a computer where the ColdFusion server is installed. If you are creating your pages on a local server (on which ColdFusion is running), then you can save the pages locally; if you are using a remote server, then you must save your pages on that server.

To publish ColdFusion pages on the Internet, you must save the pages under the web-root directory.

To save the code you just typed (to create a ColdFusion page):

  1. Create a new directory called test under the web_root directory.
  2. In the test directory, save the file as cfpage.cfm.

Browsing your code

To ensure that the code you wrote is working as expected, you must view the ColdFusion page in a browser. The following procedure describes how to view the ColdFusion page that you created earlier.

To view the ColdFusion page:

  1. Open a web browser and go to the following URL:

    http://127.0.0.1/test/cfpage.cfm

    The address 127.0.0.1 refers to the localhost and is only valid when you view pages locally. The URL for a remote site would include the IP address of the server where ColdFusion is installed; for example: http://<serveripaddress>/test/cfpage.cfm.

    The following figure shows the cfpage.cfm in the browser

    This image shows the results of step one in a browser window:Hello world, this is a ColdFusion page.Today's date is 17-Feb-02

  2. Do the following tasks:
    1. View the source code that was returned to the browser. In most browsers, you can view the source by right-clicking on page then selecting View Source.
    2. Compare the browser source code with the source code that appears in your editor. Notice that the CFML tags were processed on the page but did not appear in the source that was returned to your browser.

      As described in Chapter 1, ColdFusion processes all the instructions (CFML tags and functions) it receives on a page, and then returns the results of the instructions that your browser can interpret and display.

Comments