Intro to CFML as a language Intro to CFML as a language Intro to CFML as a language

beckonhissingInternet και Εφαρμογές Web

10 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

511 εμφανίσεις

www.cfunited.com
Intro to CFML as a language
Intro to CFML as a language
Intro to CFML as a language
Sam
Farmer
2
June
18
-
21,
2008
www.cfunited.com
About
Me
About
Me
About
Me
CF Developer 10+ years
Work at Interfolio
Blog at samfarmer.com
3
June
18
-
21,
2008
www.cfunited.com
Overview
Overview
Overview
Good to Know
Operators
Data Types
Query
Types of Files
4
June
18
-
21,
2008
www.cfunited.com
Comments
Comments
Comments
Three dashes
Never sent to browser
<!--- My comment --->
5
June
18
-
21,
2008
www.cfunited.com
Escaping
Escaping
Escaping
Always double:
##
<cfoutput>Here is a pound sign: ##</cfoutput>
“”
<cfset aString = “
a quote “” in a string”>
‘’
6
June
18
-
21,
2008
www.cfunited.com
ColdFusion
Starts
at
1
ColdFusion
ColdFusion
Starts
at
1
Starts
at
1
Loops, arrays, everything
7
June
18
-
21,
2008
www.cfunited.com
Setting
Variables
&
Strings
Setting
Variables
&
Strings
Setting
Variables
&
Strings
Use cfset
<cfset variables.myName = “Sam”>
<cfset variables.fullName = variables.myName &
“Farmer”>
<cfset variables.a = 5>
<cfset variables.b = (variables.a * 5) + 10>
CF works out the type
8
June
18
-
21,
2008
www.cfunited.com
To
Pound
or
Not
To
Pound
To
Pound
or
Not
To
Pound
To
Pound
or
Not
To
Pound
Pound Signs Needed:
in cfoutput
passing variables to attributes
<cfoutput>#variables.myName#</cfoutput>
<cfswitch expression=“#variables.myName#”>
<cfset variables.myNameUpper =
Ucase(variables.myName)>
CF very forgiving
9
June
18
-
21,
2008
www.cfunited.com
Operators
Operators
Operators
<cfif [not | !] a OPERATOR b>
lte
less than or equal
lt
less than
ge
gte
greater
than
or
equal
to
gt
greater
than
does not contain
contains
is not
neq
not
equal
is
eq
equal
10
June
18
-
21,
2008
www.cfunited.com
cfif
cfif
cfif
<cfif variables.myName eq “Sam”>
do something
<cfelseif variables.myName eq “
Fred”>
hi Fred
<cfelse>
something else
</cfif>
11
June
18
-
21,
2008
www.cfunited.com
Variables
Scopes
Variables
Scopes
Variables
Scopes
ColdFusion puts variables into scopes
Better performance
Easier debugging
12
June
18
-
21,
2008
www.cfunited.com
Variable
Types
&
Order
of
Evaluation
Variable
Types
&
Order
of
Evaluation
Variable
Types
&
Order
of
Evaluation
When using cfthread
thread global
Set
and
accessed
in
a
cfm
or
cfc
file
variables
Arguments passed into a function
arguments
When using cfthread
thread local
Set in the var scope, local to the
function
var
When looping over a query
query
column
names
13
June
18
-
21,
2008
www.cfunited.com
Variable
Types
&
Order
of
Evaluation
2
Variable
Types
&
Order
of
Evaluation
2
Variable
Types
&
Order
of
Evaluation
2
Client
variables
allow
sharing
of
user
sessions across clustered configs
client
From
cookies
set
with
cfcookie
cookie
From post forms
form
Passed
in
the
query
string
or
from
get
forms
url
Variables set when uploading a file
cffile
Information sent with every request like
users IP, browser type, etc
cgi
14
June
18
-
21,
2008
www.cfunited.com
Always
scoped
variable
types
Always
scoped
variable
types
Always
scoped
variable
types
Lasts
for,
and
unique
to,
a
request
Request
Rarely used, some information about the
server configuration, same value for a
server
server
Accessed across the whole application,
same values for an application
application
When using session variables, unique to
a user
session
Available
everywhere
15
June
18
-
21,
2008
www.cfunited.com
Complex
Data
Types
Complex
Data
Types
Complex
Data
Types
Structure
Array
List
Query
16
June
18
-
21,
2008
www.cfunited.com
Structures
Structures
Structures
Everything is a structure!
Like map or associative array
<cfset variables.myStruct =
{mon=“Monday”,tue=“Tuesday”}>
Key functions:
StructDelete
StructKeyExists
StructSort
17
June
18
-
21,
2008
www.cfunited.com
Arrays
Arrays
Arrays
<cfset variables.myArray = [“Monday”,”Tuesday”]>
Key Functions:
ArrayLen
ArrayToList
ListToArray
ArraySort
ArraySum
18
June
18
-
21,
2008
www.cfunited.com
Old
Structure
and
Array
Syntax
Old
Structure
and
Array
Syntax
Old
Structure
and
Array
Syntax
Pre ColdFusion 8:
<
cfset variables.myStruct = StructNew()>
<cfset variables.myStruct.mon = “Monday”>
<cfset variables.myStruct.tue = “Tuesday”>
<cfset variables.myArray = ArrayNew(1)>
<cfset variables.myArray[1] = “Monday”>
<cfset variables.myArray[2] = “Tuesday”>
19
June
18
-
21,
2008
www.cfunited.com
Lists
Lists
Lists
<cfset variables.myList =
“Monday,Tuesday,Wednesday
”>
Delimiter: Comma by default, other popular ones | ~
Key functions:
ListAppend
ListChangeDelims
ListFindNoCase
ListFirst
ListLast
20
June
18
-
21,
2008
www.cfunited.com
CF
Administrator
CF
Administrator
CF
Administrator
http://localhost[:8500]/cfide/administrator
Debugging
Datasources
21
June
18
-
21,
2008
www.cfunited.com
Query
Query
Query
Comes back from cfquery
Kind of array of structures
Query of Queries
Make Own queries
Returned from other tags as well like cfdirectory
22
June
18
-
21,
2008
www.cfunited.com
Forms
Forms
Forms
Get vs Post
Get = URL Scope
Post = Form Scope
cfform
23
June
18
-
21,
2008
www.cfunited.com
cfqueryparam
cfqueryparam
cfqueryparam
Always, always use with data from users
24
June
18
-
21,
2008
www.cfunited.com
Types
of
Files
Types
of
Files
Types
of
Files
.
cfm
Original
Include
Custom tag
ColdFusion Components (cfc)
25
June
18
-
21,
2008
www.cfunited.com
CF
Include
CF
Include
CF
Include
cfinclude
template=“”
Uses the variables scope of the original file
26
June
18
-
21,
2008
www.cfunited.com
Custom
Tag
Custom
Tag
Custom
Tag
Very powerful feature
Especially for presentation
Passed values are attributes
Caller scope to pass back
<cf_
<cfmodule
27
June
18
-
21,
2008
www.cfunited.com
CF
Component
(CFC)
CF
Component
(CFC)
CF
Component
(CFC)
Introduced in version 6
Collection of Functions
Use as Library or Objects
28
June
18
-
21,
2008
www.cfunited.com
User
Defined
Functions
User
Defined
Functions
User
Defined
Functions
Write your own functions
cffunction
name=“”
access=“public | private | remote”
Var scope
Always, always, always
29
June
18
-
21,
2008
www.cfunited.com
Q&A
Q&A
Q&A