+ All Categories
Home > Documents > ColdFusion Variables CF uses variables to store data in memory. There are many different types of...

ColdFusion Variables CF uses variables to store data in memory. There are many different types of...

Date post: 21-Dec-2015
Category:
View: 220 times
Download: 0 times
Share this document with a friend
Popular Tags:
32
Transcript
Page 1: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,
Page 2: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

ColdFusion Variables

• CF uses variables to store data in memory.

• There are many different types of variables; each has its own use.

• To use a variable, name it and assign it a value.

Page 3: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

Typeless

• All CF variables are typeless, which means you do not need to identify the type of the data(Such as numbers or dates.)

• Behind the scenes CF stores all the values as strings.

• When variables are accessed and expected to be of a certain type they are “cast” into the expected type.

Page 4: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

Variable Naming

• Rules– Use one word– Do not use spaces– Begin with a letter– Use only letter, and the underscore– Do not use special characters

Page 5: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

Variable Prefixes

• There are many types of variables in CF.

• Each variable has it is own scope– Where it exists– How long it exist for– Where the variable value is stored.

Page 6: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

Referencing Variables

• To reference a local variable’s value, use the variables prefix.

• Notice that you reference variables in the expression (right hand side of the equal sign) without using double quotes.

Page 7: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

<cfset firstname = “Sue”><cfset lastname=“Smith”><cfset fullname = variables.firstname +

variables.lastname>

CF would attempt to convert FirstName and LastName to numeric values which would result in an error.

Page 8: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

<cfset thenum=“40”>

<cfset newnum = variables.thenum+”25”>

<cfset the string = “new number is: variables.newnum>

Page 9: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

Creating local variables with <CFSET>

• The <cfset> tag is used to initialize the value of a variable.

• You set the value as being equal to an expression.

• The syntax for this tag is:

Page 10: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

<cfset variable_name = expression>

Page 11: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

Variables have specific values

<cfset firstname= “Sue”>

<cfset age= “29”>

• All literal values are surrounded by double quotes “Sue” “29”

Page 12: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

&

• Here, variable draws its value from two other variables:

<cfset firstname = “Sue”>

<cfset lastname=“Smith”>

<cfset fullname= variables.firstname &” ”& variables.lastname>

Page 13: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

&

• The ampersand (&) is a concatenation character and will build the string with the value of FirstName, a space and the value of last name.

• The result would be:

Page 14: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

<cfoutput>#variables.fullname#</cfoutput>

• Sue Smith

Page 15: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

<CFQUERY>

Page 16: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,
Page 17: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,
Page 18: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

CFQUERY

Page 19: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,
Page 20: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,
Page 21: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,
Page 22: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,
Page 23: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,
Page 24: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,
Page 25: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

CF Functions

• CFML is made up of two primary language elements– Tags – perform operations such as accessing a

database, evaluating a condition

– Functions- Return (possibly process) data and do things such as getting the current date and time, converting text to uppercase, and rounding a number to its nearest integer.

Page 26: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

• #Now()# is an instruction telling CF to execute a function named Now()- a function that returns the current date and time.

• What happens – If no pound signs?– If put outside the cfoutput tag?

Page 27: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

• Format of that date function is not entirely readable.

• Another function, DateFormat( ) can help here.

• DateFormat () role is to format dates so they are readable.

Page 28: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

• DateFormat is an example of a function that accepts (and requires) that data must be passed to it – after all it needs to know which date you want to format to display.

• #DateFormat(Now())# tells CF to format the date returned by the Now() function.

Page 29: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

NESTed

• Passing a function as a parameter to another function is referred to as NESTING.

• The Now() function is said to be NESTED in the DateFormat() function.

Page 30: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

DateFormat()

• DateFormat() takes second optional attribute: – A format mask used to describe the output format.

#DateFormat(Now(), “MMMM-DD-YY”)#

#DateFormat(Now(), “MM-DD-YY”)#

#DateFormat(Now(), “DDD,MMMM DD-YYYY”)#

Parameters passed to a function are always seperated by comma.

Page 31: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

RecordCount

RecordCount contains the total number of records returned by the query.

Number of rows returned:

<cfoutput>

#queryname.recordcount#

</cfoutput>

Page 32: ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,

CurrentRow

<cfoutput query =“queryname”>

Row#queryname.currentrow# of #queryname.recordcount#

</cfoutput>


Recommended