Presentation is loading. Please wait.

Presentation is loading. Please wait.

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,

Similar presentations


Presentation on theme: "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,"— Presentation transcript:

1

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, name it and assign it a value.

3 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.

4 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

5 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.

6 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.

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

8

9 Creating local variables with The 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:

10

11 Variables have specific values All literal values are surrounded by double quotes “Sue” “29”

12 & Here, variable draws its value from two other variables:

13 & 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:

14 #variables.fullname# Sue Smith

15

16

17

18 CFQUERY

19

20

21

22

23

24

25 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.

26 #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?

27 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.

28 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.

29 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.

30 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.

31 RecordCount RecordCount contains the total number of records returned by the query. Number of rows returned: #queryname.recordcount#

32 CurrentRow Row#queryname.currentrow# of #queryname.recordcount#


Download ppt "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,"

Similar presentations


Ads by Google