Cold Fusion 3.1 Tips
Way back in the '90s I did some ColdFusion work - it was really fun and cutting edge at the time, ... but the world moves on.
- Setting a variable:
<cfset #OK# = 'NOT_OK'>
- Logical branching:
<cfif #MYCOUNT# EQ 0> statements... <cfelseif #MYCOUNT# GE 1> statements... <cfelse> statements... </cfif>
- Querys etc:
<CFQUERY datasource="mydatabase" name="getpassword" SQL="Select password from Passwords where password = '#PASSWORD#'"> </CFQUERY> <cfif #getpassword.RecordCount# GT 0> <cfset #OK# = 'OK'> </cfif>
- Stuff info into database
<CFQUERY datasource="mydatabase"> Update mytable SET FirstName='#FirstName#', LastName='#LastName#', WHERE EmployeeID=#EmployeeID# </CFQUERY>
- to create a carriage return or other control character
#CHR(013)#
- Goto another page:
<CFLOCATION URL="NewPage.cfm" ADDTOKEN="No">
- Check for the existance of a variable (great for detecting if a
checkbox has been checked):
<CFIF IsDefined("InState")> <cfset #InState# = 1> <cfelse> <cfset #InState# = 0> </CFIF>
- Call a stored procedure:
<cfquery datasource="mydatabase" name="mystoredp"> { CALL sp_mystoredproc ('#NAME#') } </CFQUERY>
- Get the current file's name
<cfset #CURRENTFILE# = #GetFileFromPath(GetTemplatePath())#>
- Use cookies
This sets a cookie that will expire in 100 days. If the expires field is omitted, the cookie expires at the end of the session.
<CFCOOKIE NAME="color" VALUE="red" EXPIRES="100">
This sets the value of a cookie
<cfset #Cookie.color# = "green">
This prints the value of a cookie
<cfoutput>value of cookie color is #Cookie.color#</cfoutput>
Wierd fact about ColdFusion: If a CFLOCATION is done on the same page, the setting of a cookie value does NOT take place.