Intro to CFML as a language
Intro to CFML as a language
Sam Farmer
no notes exist for this slide
About Me
About Me
CF Developer 10+ years
Work at Interfolio
Blog at samfarmer.com
no notes exist for this slide
Overview
Overview
Good to Know
Operators
Data Types
Query
Types of Files
no notes exist for this slide
Comments
Comments
Three dashes
Never sent to browser
<!--- My comment --->
no notes exist for this slide
Escaping
Escaping
Always double:
##
<cfoutput>Here is a pound sign: ##</cfoutput>
ââ
<cfset aString = âa quote ââ in a stringâ>
ââ
no notes exist for this slide
ColdFusion Starts at 1
ColdFusion Starts at 1
Loops, arrays, everything
no notes exist for this slide
Setting Variables amp 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
no notes exist for this slide
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
no notes exist for this slide
Operators
Operators
<cfif [not | !] a OPERATOR b>
no notes exist for this slide
cfif
cfif
<cfif variables.myName eq âSamâ>
do something
<cfelseif variables.myName eq âFredâ>
hi Fred
<cfelse>
something else
</cfif>
no notes exist for this slide
Variables Scopes
Variables Scopes
ColdFusion puts variables into scopes
Better performance
Easier debugging
no notes exist for this slide
Variable Types amp Order of Evaluation
Variable Types & Order of Evaluation
no notes exist for this slide
Variable Types amp Order of Evaluation 2
Variable Types & Order of Evaluation 2
no notes exist for this slide
Always scoped variable types
Always scoped variable types
no notes exist for this slide
Complex Data Types
Complex Data Types
Structure
Array
List
Query
no notes exist for this slide
Structures
Structures
Everything is a structure!
Like map or associative array
<cfset variables.myStruct = {mon=âMondayâ,tue=âTuesdayâ}>
Key functions:
StructDelete
StructKeyExists
StructSort
no notes exist for this slide
Arrays
Arrays
<cfset variables.myArray = [âMondayâ,âTuesdayâ]>
Key Functions:
ArrayLen
ArrayToList
ListToArray
ArraySort
ArraySum
no notes exist for this slide
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â>
no notes exist for this slide
Lists
Lists
<cfset variables.myList = âMonday,Tuesday,Wednesdayâ>
Delimiter: Comma by default, other popular ones | ~
Key functions:
ListAppend
ListChangeDelims
ListFindNoCase
ListFirst
ListLast
no notes exist for this slide
CF Administrator
CF Administrator
http://localhost[:8500]/cfide/administrator
Debugging
Datasources
no notes exist for this slide
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
no notes exist for this slide
Forms
Forms
Get vs Post
Get = URL Scope
Post = Form Scope
cfform
no notes exist for this slide
cfqueryparam
cfqueryparam
Always, always use with data from users
no notes exist for this slide
Types of Files
Types of Files
.cfm
Original
Include
Custom tag
ColdFusion Components (cfc)
no notes exist for this slide
CF Include
CF Include
cfinclude
template=ââ
Uses the variables scope of the original file
no notes exist for this slide
Custom Tag
Custom Tag
Very powerful feature
Especially for presentation
Passed values are attributes
Caller scope to pass back
<cf_
<cfmodule
no notes exist for this slide
CF Component CFC
CF Component (CFC)
Introduced in version 6
Collection of Functions
Use as Library or Objects
no notes exist for this slide
User Defined Functions
User Defined Functions
Write your own functions
cffunction
name=ââ
access=âpublic | private | remoteâ
Var scope
Always, always, always
no notes exist for this slide
QampA
no notes exist for this slide