Cold Fusion Tutorial

Download Report

Transcript Cold Fusion Tutorial

Cold Fusion Tutorial
Mohammad Shamma
SIMS 213 Spring 1999
Cold Fusion Tutorial
• Brief overview of CF Three-tiered
architecture
• Building CF queries
• Specifying CF query output
• Building CF data input forms
• Inserting data from a CF form
• A sample CF database “drill-down”
application
Cold Fusion Architecture
Cold Fusion Architecture
As shown in the previous slide, the Cold
Fusion Application Server (CFAS)
processes “.cfm” templates by parsing only
CFML (Cold Fusion Markup Language)
tags within the template.
CFML looks almost exactly like HTML which
makes building “.cfm” templates easier for
user who are familiar with HTML.
Intro to CFML
• This is an example of CFML query that
produces a student list.
<cfquery name=“student_list” datasource=“student_db”>
SELECT studentID, studentName
FROM students
<cfquery>
The required attributes for <cfquery> are “name” and “datasource.” “Name” refers to an
arbitrary name so that you can refer to this query in <cfoutput> and “datasource” refers
to the unique datasource name specified in the ODBC Administrator tool in Microsoft
Windows. For further informaiton on ODBC please see FAQ at
(http://www.roth.net/odbc/odbcfaq.htm).
CFML (cont’d)
• Next, the <cfoutput> tag is required to
display the output of a particular <cfquery>.
<cfquery name=“student_list” datasource=“student_db”>
SELECT studentID, studentName
FROM students
</cfquery>
<cfoutput query=“student_list”>
#studentID# -- #studentName#
</cfoutput>
Although the <cfquery> tags do not have to be placed within the <HTML> </HTML> tags,
the <cfoutput> must be placed within these tags.
CFML
•
The following output will be displayed with whatever HTML formatting is
inserted inside the <cfoutput> </cfoutput> tags. So if we wanted to apply
HTML formatting to one of the output fields in the previous example, we
would do so like this:
<cfoutput query=“student_list”>
<B> #studentID#</B> -- #studentName#
</cfoutput>
The <B></B> tags around the #studentID# output field will apply a “Bold” font style to that
particular field.
What would this “.cfm” file look like?
Once finished the “.cfm” file would look like this.
<cfquery name=“student_list” datasource=“student_db”>
SELECT studentID, studentName
FROM students
</cfquery>
<HTML>
<HEAD>
<TITLE>CF Query example</TITLE>
</HEAD>
<BODY>
<cfoutput query=“student_list”>
#studentID# -- #studentName#
</cfoutput>
</BODY>
</HTML>
CF Data Input Forms
• A typical way to build a CF based data input
form is to create a typical HTML form and
assign the appropriate field names as
attributes within your form.
Ex.
<input type=“text” name=“studentID” maxlength=“10”>
<input type=“text” name=“studentName” maxlength=“25”>
*Notice that the names of these two inputs correspond to the
field names used in the previous example.
CF Data Input Forms
• Next you need to specify the form action,
which in this case is the page that will insert
the data from the form into the “student_db”
datasource.
<FORM ACTION=“addStudent.cfm” method=“POST”>
<input type=“text” name=“studentID” maxlength=“10”>
<input type=“text” name=“studentName” maxlength=“25”>
<input type=“submit” name=“submit” value=“Insert Student”>
Inserting data from a form.
• The tag <CFINSERT> is an easy way to
insert data from a form into a database
table. The following is an example of what
would be placed at the top of the
“addStudent.cfm” action template:
<cfinsert datasource=“student_db” tablename=“students”>
*Note that we are using the same datasource and that that table to be updated is specified as
well.
Sample CFML files
• Along with these notes are a set of “.cfm”
files that read and display simple data from
a datasource, add data to that datasource
and perform complex searches to “drilldown” into that datasource.
• The datasource for these files is a Microsoft
Access database file called (tutorial.mdb).
CFML Sample files
• The file “grade_report.cfm” produces a list
of students and their grades from particular
courses.
• The files
“addStudentGrade_EntryForm.cfm” and
“addStudentgrade_EntryAction.cfm” allow
data to be inserted into the database.
CFML Sample files
• Finally the last set of files allow you to
build complex data “drill-down”
applications to the database:
–
–
–
–
studentsearch_Search.cfm
studentsearch_Result.cfm
studentsearch_Detail.cfm
studentsearch_AppendCriteria.cfm
More on Cold Fusion
• If you want to know more about Cold
Fusion (http://www.allaire.com)
• Further documentation can be viewed from
(http://www.allaire.com/Documents/cf4docs.cfm)