Simplifying Solutions
Simple reminder guide to using CFSCRIPT version of CF Tags. This is a combination of Peter Freitag’s list and some posts by Ray Camden
Dump:
1 | writedump(var=server, top=2, label="line 32"); |
include:
1 2 3 4 | include "another.cfm"; /* ...or a dynamic version... */ x = "yetanother.cfm"; include x; |
cflocation
1 | location(url=“test2.cfm”,addtoken=false); |
cfparam
1 | param name=“y” default=1 min=1; |
lock
1 2 3 | lock type=“exlcusive” name=“somelock” timeout=“30” { /* locked stuff here */ } |
log
1 | writelog(file="application", text="log entry"); |
savecontent
1 | savecontent variable="newvar" { include "another.cfm"; } |
tracing
1 | trace(category="cat", text=“trace”); |
thread
1 | thread name="backgroundtask" priority="low" { ... } |
transaction
1 | transaction action=“begin” { ... } |
throw exception
1 | throw(message="not logged in", detail="you must login to continue"); |
stop
1 | abort; |
for loop
1 2 3 | for (i=1;i LTE ArrayLen(array);i=i+1) { WriteOutput(array[i]); } |
switch case
1 2 3 4 5 6 7 8 9 10 | switch(fruit) { case "apple": WriteOutput("I like Apples"); break; case "orange": WriteOutput("I like Oranges"); break; default: WriteOutput("I like fruit"); } |
for loop on a structure
1 2 3 4 5 6 7 | struct = StructNew(); struct.one = "1"; struct.two = "2"; for (key in struct) { WriteOutput(key); } //OUTPUTS onetwo |
for loop on an array
1 2 3 4 5 | cars = ["Ford","Dodge"]; for (car in cars) { WriteOutput(car); } //OUTPUTS FordDodge |
for loop on a Query
1 2 3 4 5 6 7 | cars = QueryNew("make,model", "cf_sql_varchar,cf_sql_varchar", [["Ford", "T"],["Dodge","30"]]); for (car in cars) { WriteOutput("Model " & car.model); } //OUTPUTS Model TModel 30 |
create a structure literal
1 | product = {id=1, name="Widget"}; |
create an array literal
1 | fruit = ["apples", "oranges"]; |
Comments Closed.