coldfusion variables cf uses variables to store data in memory. there are many different types of...
Post on 21-Dec-2015
223 views
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/1.jpg)
![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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/2.jpg)
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/3.jpg)
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/4.jpg)
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/5.jpg)
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/6.jpg)
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/7.jpg)
<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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/8.jpg)
<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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/9.jpg)
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/10.jpg)
<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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/11.jpg)
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/12.jpg)
&
• 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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/13.jpg)
&
• 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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/14.jpg)
<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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/15.jpg)
<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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/16.jpg)
![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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/17.jpg)
![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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/18.jpg)
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/19.jpg)
![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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/20.jpg)
![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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/21.jpg)
![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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/22.jpg)
![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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/23.jpg)
![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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/24.jpg)
![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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/25.jpg)
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/26.jpg)
• #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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/27.jpg)
• 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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/28.jpg)
• 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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/29.jpg)
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/30.jpg)
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/31.jpg)
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,](https://reader035.vdocuments.mx/reader035/viewer/2022062313/56649d635503460f94a45acc/html5/thumbnails/32.jpg)
CurrentRow
<cfoutput query =“queryname”>
Row#queryname.currentrow# of #queryname.recordcount#
</cfoutput>