Notes from CF Class 1
(Janet's interpretation of Edlyn's
notes--plus some code)
What is CF
An Interface
between web and database. Cold Fusion Markup Language
- macro language for
HTML – compare to mail mege.
HTML is not a
programming language,
it has
tags,
it is
file based (separate files instead of one big file like Access or VBPPt),
it is
stateless (each page is independent/does not have information from the page
before),
Many similarities between HTML and Cold Fusion--but you can program in CF
HTML code cannot be protected--users can always view
it. They cannot see your CF code. The
CF server processes it and sends it to the user as HTML.
ASP: Active Server
Pages--lets you put out web pages--not html based--more like VB. CF's competition.
Apache web server has been installed.
Homesite: From
Allaire the source of CF, this is an editor/code generator for html and cf
Path to class files
is Network Neighborhood/Ice/wwwroot/cf-class
The following were exercises that Michael set in class and
helped us get up and running.
First Example: Hello World HTML
To access your index.html file (using your folder and your
index.html file)
http://207.196.87.5/janet/ (the numbers are the IP number
address of the machine – instead of machine name such as www.byteback.org) Note: the internet
address slashes / go the opposite way from Windows slashes \ in file names and
paths.
<html>
<head>
<title>
This is Janet's Hello World
</title>
</head>
<body
bgcolor="aqua" text="red">
<h1>Hello World and hello Michael!</h1>
</body>
</html>
Second Example: Cold Fusion If, Set
<CFIF hour (
now( ) ) gt 18> gt
means greater than (can use > as that is tag delimiter in HTML!)
some code and/or text
</CFIF>
The function now() gets the current date/time on the server.
The function hour() gets the hour from the date/time value.
If the statement is true, the next line will be processed
and the text will be sent to the
If the statement is false, the CF server drops below the
close CFIF tag.
You can also assign values to variables: <cfset CurrentHour=hour(now())>
This sets CurrentHour equal to the value obtained by the
functions hour and now
Here is a file called
first.cfm file using CurrentHour
<html>
<head>
<title>
Using If and Set
</title>
</head>
<body
bgcolor="aqua" text="red">
<h1>Hello World and hello Michael!</h1>
<cfset CurrentHour =hour(now())>
<cfoutput>
#h#
</cfoutput>
<cfif CurrentHour gt 18
>
It is later than 6 PM
<cfelseif CurrentHour gt 2 and CurrentHour lte 6>
It is too early!
<cfelse>
Tea break!
</cfif>
</body>
</html>
CF is similar to other programming languages. You can add a CFELSEIF and CFELSE to provide
other options.
Third Example: A Simple Form
The Input page puts two text input areas and a button on the
page.
<html>
<head>
<title>
Input page
</title>
</head>
<body bgcolor="Lime" text="blue">
<form action="action.cfm"
method="post">
<input type="text"
name="FirstName">
<input type="text"
name="LastName">
<input
type="submit"
name="submit">
</form>
</body>
</html>
The action page
<html>
<head>
<title>Action
Page</title>
</head>
<body bgcolor="red" text="white">
<font size=6>Here is the output.
</font>
<cfoutput><h3>First Name
<P>Last Name</h3>
<cfif lastname is "Lathan">
<font size=7 color="yellow">#FirstName#
<P>#UPPER(LastName)#</font>
<cfelse>
<font size=7 color="blue">#FirstName#
<P>#UPPER(LastName)#</font>
</cfif>
</cfoutput>
</body>
</html>
The is a nice summary of forms at http://junior.apk.net/~jbarta/tutor/forms/quik-index.html
We also discussed CFABORT to end process of a page early.
<cfif not isdefined("firstname")>
This is an abort.
<cfabort>
</cfif>
and cf comment tags <!--- This is a comment ---> with one more dash than html.
Note if you use HTML comments with two dashes to comment out
CF code then the code will still run and you page will not behave as you
expect!