File size: 50,205 Bytes
08c8a6d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 |
coldfusion
#coldfusion
Table of Contents
About
Chapter 1: Getting started with coldfusion
Remarks
Versions
Examples
Installation or Setup
Linux (Ubuntu) Installation
Lucee (Open Source)
ColdFusion / CFML Interpretor
Nginx
Adobe (Closed Source)
ColdFusion / CFML Interpretor
Nginx
Hello World
Chapter 2: CFLOOP How-To
Remarks
Examples
Looping through a collection using CFML tags.
Looping through a collection using CFSCRIPT.
Index
Parameters
Basic index loop
Increase step to 2
Decrement step by 1
CFLoop in a Function
ColdFusion 11 through current
Condition
Tag syntax
Parameters
Generated HTML
1
2
2
2
3
3
3
3
3
3
4
4
4
5
7
7
7
7
7
7
7
8
8
9
9
10
10
10
10
10
CFScript
Previous to ColdFusion 8
ColdFusion 8 through current
ColdFusion 11 through current
Generated HTML
Date or time range
Query
Parameters
Example query
Tag syntax
Generated HTML
Limiting output to specific rows
Grouping Output
CFScript
ColdFusion 6 (MX) though current
ColdFusion 8 though current
ColdFusion 10 though current
ColdFusion 11 though current
List
Tag syntax
Parameters
Generated HTML
CFScript
Previous to ColdFusion 8
ColdFusion 8 through current
ColdFusion 9 through current
ColdFusion 11 through current
Generated HTML
Array
Tag syntax
ColdFusion 8 through current
10
11
11
11
11
11
11
11
12
12
12
13
13
14
15
15
15
15
16
16
16
16
16
16
17
17
17
17
17
17
17
Parameters
Generated HTML
ColdFusion 2016 through current
Parameters
Generated HTML
CFScript
Previous to ColdFusion 8
ColdFusion 8 through current
ColdFusion 9 through current
ColdFusion 11 through current
Generated HTML
File
Structure
Tag syntax
Parameters
Using Structure Functions
Implicit Structure Syntax
Generated HTML
CFScript
Output the structure's keys
Generated HTML
Output the value of the structure's keys
Using Structure Functions
Implicit Structure Syntax
ColdFusion 11 through current
Generated HTML
Index Loop
Conditional Loop
Query Loop
List Loop
File Loop
COM Collection/Structure Loops
18
18
18
18
19
19
19
19
19
19
19
20
20
20
20
20
20
21
21
21
21
21
21
21
22
22
22
22
22
23
23
23
Chapter 3: cfquery
Parameters
Examples
Using cfquery within a Function
Query of Query
Function Calls
User.cfc
Chapter 4: ColdFusion Arrays
Syntax
Parameters
Remarks
Examples
Creating Arrays
Creating arrays explicitly using ArrayNew()
History
Declaration
Using ArrayAppend()
Creating 1-D Array Implicitly
Create 2-D Array Implicitly
Array in CFScript
Similarly, for 2 Dimension Array:
General information
Chapter 5: Creating REST APIs in coldfusion
Introduction
Examples
Creating backend
The interface
Chapter 6: Database Queries
Examples
Working with databases
Basic Example
24
24
24
24
24
24
24
26
26
26
26
26
26
26
26
26
27
28
29
30
31
31
32
32
32
32
32
33
33
33
33
Authentication
Cached Queries
Limiting the Number of Records Returned
Timeouts
Chapter 7: How to invoke a private method dynamically
Remarks
Examples
CFML
CFSCRIPT (CF10+)
Chapter 8: Scopes in Coldfusion
Introduction
Examples
Request Scopes
Global Scopes
Components and functions
Custom tags
Common scopes
Overview
Chapter 9: Variables
Parameters
Examples
Using cfset
Using cfparam
Checking if a Variable Exists
Setting a variable scope
Chapter 10: Working with RegExp Replace callbacks
Introduction
Parameters
Remarks
Examples
User defined REReplaceCallback function
Using REReplaceCallback function
34
34
35
35
36
36
36
36
36
37
37
37
37
37
37
37
38
38
39
39
39
39
39
40
40
42
42
42
42
42
43
43
Credits
44
About
You can share this PDF with anyone you feel could benefit from it, downloaded the latest version
from: coldfusion
It is an unofficial and free coldfusion ebook created for educational purposes. All the content is
extracted from Stack Overflow Documentation, which is written by many hardworking individuals at
Stack Overflow. It is neither affiliated with Stack Overflow nor official coldfusion.
The content is released under Creative Commons BY-SA, and the list of contributors to each
chapter are provided in the credits section at the end of this book. Images may be copyright of
their respective owners unless otherwise specified. All trademarks and registered trademarks are
the property of their respective company owners.
Use the content presented in this book at your own risk; it is not guaranteed to be correct nor
accurate, please send your feedback and corrections to info@zzzprojects.com
https://riptutorial.com/
1
Chapter 1: Getting started with coldfusion
Remarks
This section provides an overview of what coldfusion is, and why a developer might want to use it.
It should also mention any large subjects within coldfusion, and link out to the related topics. Since
the Documentation for coldfusion is new, you may need to create initial versions of those related
topics.
Versions
Version
Release Date
Cold Fusion version 1.0
1995-07-02
Cold Fusion version 1.5
1996-01-01
Cold Fusion version 2.0
1996-10-01
Cold Fusion version 3.0
1997-06-01
Cold Fusion version 3.1
1998-01-01
ColdFusion version 4.0
1998-11-01
ColdFusion version 4.5.1
1999-11-01
ColdFusion version 5.0
2001-06-01
ColdFusion MX version 6.0 2002-05-01
ColdFusion MX version 6.1 2003-07-01
ColdFusion MX 7
2005-02-07
ColdFusion 8
ColdFusion 9
2007-07-30
2009-10-05
ColdFusion 10
2012-05-15
ColdFusion 11
2014-04-29
ColdFusion 2016
2016-02-16
https://riptutorial.com/
2
Examples
Installation or Setup
Linux (Ubuntu) Installation
Lucee (Open Source)
ColdFusion / CFML Interpretor
Download the appropriate file from their site (http://lucee.org/downloads.html) and execute their
installer
wget http://cdn.lucee.org/downloader.cfm/id/155/file/lucee-5.0.0.252-pl0-linux-x64-
installer.run
sudo chmod +x lucee-5.0.0.252-pl0-linux-x64-installer.run
sudo ./lucee-5.0.0.252-pl0-linux-x64-installer.run
Step through installer.
Nginx
Install Nginx on your server
sudo apt-get install nginx
Edit your /etc/nginx/sites-available/default
server {
listen 80;
server_name _;
root /opt/lucee/tomcat/webapps/ROOT;
index index.cfm index.html index.htm;
#Lucee Admin should always proxy to Lucee
location /lucee {
include lucee.conf;
}
#Pretty URLs
location / {
try_files $uri /index.cfm$uri?$is_args$args;
include lucee.conf;
}
location ~ \.cfm {
include lucee.conf;
}
https://riptutorial.com/
3
location ~ \.cfc {
include lucee.conf;
}
}
Edit /etc/nginx/lucee.conf
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Reload nginx
sudo service nginx reload
Access the Lucee Server admin here:
127.0.0.1/lucee/admin/server.cfm
or
127.0.0.1:8888/lucee/admin/server.cfm
Your root web directory lives here:
/opt/lucee/tomcat/webapps/ROOT
Adobe (Closed Source)
ColdFusion / CFML Interpretor
Download the appropriate file from their site (
https://www.adobe.com/products/coldfusion/download-trial/try.html) and execute their installer
wget <URL>/ColdFusion_2016_WWEJ_linux64.bin
sudo chmod +x ColdFusion_2016_WWEJ_linux64.bin
sudo ./ColdFusion_2016_WWEJ_linux64.bin
Step through installer. Make sure you select the internal web server (port 8500)
Nginx
Install Nginx on your server
sudo apt-get install nginx
https://riptutorial.com/
4
Edit your /etc/nginx/sites-available/default
server {
listen 80;
server_name _;
root /opt/coldfusion2016/cfusion/wwwroot;
index index.cfm index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ^~ /CFIDE/administrator {
deny all;
}
location ~* \.(cfm|cfml|cfc|html)$ {
include /etc/nginx/conf/dc_tomcat_connector.conf;
}
location ^~ /rest {
include tomcatconf;
}
}
Edit /etc/nginx/tomcat.conf
proxy_pass http://127.0.0.1:8500;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
Reload nginx
sudo service nginx reload
Access the Adobe ColdFusion Server admin here:
127.0.0.1:8500/CFIDE/administrator/index.cfm
Your root web directory lives here:
/opt/coldfusion2016/cfusion/wwwroot
Hello World
File: test.cfm
Tag Implementation
https://riptutorial.com/
5
<cfoutput>Hello World!</cfoutput>
CFScript Implementation
<cfscript>
writeOutput("Hello World!");
</cfscript>
Read Getting started with coldfusion online: https://riptutorial.com/coldfusion/topic/913/getting-
started-with-coldfusion
https://riptutorial.com/
6
Chapter 2: CFLOOP How-To
Remarks
Big thanks to
β’
β’
Pete Freitag for his CFScript Cheat Sheet
Adam Cameron for CF 11: CFLOOP in CFScript is Very Broken (and it still is in CF 2016).
Examples
Looping through a collection using CFML tags.
<!--- Define collection --->
<cfset attributes = {
"name": "Sales",
"type": "text",
"value": "Connection"
}>
<!---
cfloop tag with attribute collection can be used to
loop through the elements of a structure
--->
<cfloop collection=#attributes# item="attribute">
<cfoutput>
Key : #attribute#, Value : #attributes[attribute]#
</cfoutput>
</cfloop>
Looping through a collection using CFSCRIPT.
<cfscript>
/*define collection*/
attributes = {
"name": "Sales",
"type": "text",
"value": "Connection"
};
for(attribute in attributes){
/* attribute variable will contain the key name of each key value pair in loop */
WriteOutput('Key : ' & attribute & ', Value : ' & attributes[attribute] & '<br/>');
}
</cfscript>
Index
Parameters
https://riptutorial.com/
7
Attribute Required Type
Default Description
index
true
string
Variable name for the loop's index. Defaults to
the variables scope.
from
to
true
true
numeric
numeric
Starting value for the index.
Ending value for the index.
step
false
numeric 1
Value by which to increase or decrease the
index per iteration.
Basic index loop
Final value of x is 10.
<!--- Tags --->
<cfoutput>
<cfloop index="x" from="1" to="10">
<li>#x#</li>
</cfloop>
</cfoutput>
<!--- cfscript --->
<cfscript>
for (x = 1; x <= 10; x++) {
writeOutput('<li>' & x & '</li>');
}
</cfscript>
<!--- HTML Output --->
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Increase step to 2
Final value of x is 11.
<!--- Tags --->
<cfoutput>
<cfloop index="x" from="1" to="10" step="2">
<li>#x#</li>
</cfloop>
</cfoutput>
<!--- cfscript --->
<cfscript>
for (x = 1; x <= 10; x += 2) {
https://riptutorial.com/
8
writeOutput('<li>' & x & '</li>');
}
</cfscript>
<!--- HTML Output --->
- 1
- 3
- 5
- 7
- 9
Decrement step by 1
Final value of x is 0.
<!--- Tags --->
<cfoutput>
<cfloop index="x" from="10" to="1" step="-1">
<li>#x#</li>
</cfloop>
</cfoutput>
<!--- cfscript --->
<cfscript>
for (x = 10; x > 0; x--) {
writeOutput('<li>' & x & '</li>');
}
</cfscript>
<!--- HTML Output --->
- 10
- 9
- 8
- 7
- 6
- 5
- 4
- 3
- 2
- 1
CFLoop in a Function
Make sure to var or local scope the index inside a function. Foo() returns 11.
<!--- var scope --->
<cffunction name="foo" access="public" output="false" returntype="numeric">
<cfset var x = 0 />
<cfloop index="x" from="1" to="10" step="1">
<cfset x++ />
</cfloop>
<cfreturn x />
</cffunction>
<!--- Local scope --->
<cffunction name="foo" access="public" output="false" returntype="numeric">
<cfloop index="local.x" from="1" to="10" step="1">
<cfset local.x++ />
https://riptutorial.com/
9
</cfloop>
<cfreturn local.x />
</cffunction>
ColdFusion 11 through current
The cfscript function cfloop has no support for index as a stand alone counter
mechanism.
Condition
Tag syntax
Parameters
Attribute Required Type Default Description
Condition that manages the loop. Cannot contain
math symbols like <, > or =. Must use ColdFusion
text implementations like less than, lt, greater than
, gt, equals or eq.
condition
true
string
Final value of x is 5.
<cfset x = 0 />
<cfoutput>
<cfloop condition="x LT 5">
<cfset x++ />
<li>#x#</li>
</cfloop>
</cfoutput>
Generated HTML
This will also have a line break between each line of HTML.
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
CFScript
https://riptutorial.com/
10
Previous to ColdFusion 8
<cfscript>
x = 0;
while (x LT 5) {
x = x + 1;
writeOutput('<li>' & x & '</li>');
}
</cfscript>
ColdFusion 8 through current
<cfscript>
x = 0;
while (x LT 5) {
x = x++;
writeOutput('<li>' & x & '</li>');
}
</cfscript>
ColdFusion 11 through current
The cfscript function cfloop has no support for condition.
Generated HTML
Notice that the cfscript output is all on one line.
<li>one</li><li>two</li><li>three</li><li>four</li>
Date or time range
Example for date or time range.
Query
Consider the table dbo.state_zip, which contains the columns city, statecode and zipcode and has
over 80,000 records.
Parameters
Attribute Required Type
Default Description
query
true
string
The variable name of a query object.
startrow
false
numeric
The starting row index of the query object.
https://riptutorial.com/
11
Attribute Required Type
Default Description
endrow
false
numeric
The ending row index of the query object.
group
false
string
The query column name on which to group
records.
Example query
<cfquery name="geo" datasource="reotrans-dev">
SELECT city, stateCode, zipCode
FROM dbo.state_zip
</cfquery>
Tag syntax
Using the query object geo as the source for cfloop. Since the table dbo.state_zip has so many
records, the HTML generated will take quite some time. This example shows only the first 20
records' worth of HTML.
<cfoutput>
<ul>
<cfloop query="geo">
<!--- Scope the column names with the query name. --->
<li>#geo.city# | #geo.stateCode# | #geo.zipCode#</li>
</cfloop>
</ul>
</cfoutput>
Generated HTML
<ul>
<li>100 PALMS | CA | 92274</li>
<li>1000 PALMS | CA | 92276</li>
<li>12 MILE | IN | 46988</li>
<li>1ST NATIONAL BANK OF OMAHA | NE | 68197</li>
<li>29 PALMS | CA | 92277</li>
<li>29 PALMS | CA | 92278</li>
<li>3 STATE FARM PLAZA | IL | 61710</li>
<li>3 STATE FARM PLAZA | IL | 61791</li>
<li>30TH STREET | PA | 19104</li>
<li>3M CORP | MN | 55144</li>
<li>65TH INFANTRY | PR | 00923</li>
<li>65TH INFANTRY | PR | 00924</li>
<li>65TH INFANTRY | PR | 00929</li>
<li>65TH INFANTRY | PR | 00936</li>
<li>7 CORNERS | VA | 22044</li>
<li>88 | KY | 42130</li>
<li>9 MILE POINT | LA | 70094</li>
<li>A A R P INS | PA | 19187</li>
<li>A A R P PHARMACY | CT | 06167</li>
https://riptutorial.com/
12
<li>A H MCCOY FEDERAL BLDG | MS | 39269</li>
</ul>
Limiting output to specific rows
To limit the query's output to a specific range of rows, specify startrow and endrow.
<cfloop query="geo" startrow="100" endrow="150">
<li>#geo.city# | #geo.stateCode# | #geo.zipCode#</li>
</cfloop>
Grouping Output
In the example data, the same state listed multiple times in relation to the multiple cities that are
associated to each state. You can also see the same city listed multiple times in relation to the
multiple zip codes associated to each city.
Let's group the output by state first. Notice the 2nd instance of cfloop wrapped around the content
that will be output under the stateCode grouped content.
<cfoutput>
<ul>
<cfloop query="geo" group="stateCode">
<!--- Scope the column names with the query name. --->
<li>#geo.stateCode#
<ul>
<cfloop>
<li>#geo.city# | #geo.zipCode#</li>
</cfloop>
</ul>
</li>
</cfloop>
</ul>
</cfoutput>
Generated HTML (extract) from one grouped cfloop tag.
<ul>
<li>AK
<ul>
<li>KONGIGANAK | 99545</li>
<li>ADAK | 99546</li>
<li>ATKA | 99547</li>
<!-- etc. -->
</ul>
</li>
<li>AL
<ul>
<li>ALEX CITY | 35010</li>
<li>ALEXANDER CITY | 35010</li>
<li>ALEX CITY | 35011</li>
<!-- etc. -->
</ul>
https://riptutorial.com/
13
</li>
<!-- etc. -->
</ul>
Finally, let's group the output by stateCode, then by city in order to see all the zipCode entries per
city. Notice the 2nd cfloop is now grouped by city and a 3rd cfloop exists to output the zipCode
data.
<cfoutput>
<ul>
<cfloop query="geo" group="stateCode">
<li>#geo.stateCode#
<ul>
<cfloop group="city">
<li>#geo.city#
<ul>
<cfloop>
<li>#geo.zipCode#</li>
</cfloop>
</ul>
</li>
</cfloop>
</ul>
</li>
</cfloop>
</ul>
</cfoutput>
Generated HTML (extract) from two grouped cfloop tags.
<ul>
<li>AK
<ul>
<li>ADAK
<ul>
<li>99546</li>
<li>99571</li>
</ul>
</li>
<li>AKHIOK
<ul>
<li>99615</li>
</ul>
</li>
<!--- etc. --->
<li>BARROW
<ul>
<li>99723</li>
<li>99759</li>
<li>99789</li>
<li>99791</li>
</ul>
</li>
<!--- etc. --->
</ul>
</li>
<!--- stateCodes etc. --->
</ul>
https://riptutorial.com/
14
CFScript
ColdFusion 6 (MX) though current
<cfscript>
for (x = 1; x LTE geo.recordcount; x = x + 1) {
writeOutput( '<li>' & geo.city[x] & ' | ' &
geo.stateCode[x] & ' | ' & geo.zipCode[x] & '</li>');
}
</cfscript>
ColdFusion 8 though current
<cfscript>
for (x = 1; x <= geo.recordcount; x++) {
writeOutput( '<li>' & geo.city[x] & ' | ' &
geo.stateCode[x] & ' | ' & geo.zipCode[x] & '</li>');
}
</cfscript>
ColdFusion 10 though current
With the FOR IN syntax, x is a query row object, not the row index.
<cfscript>
for (x in geo) {
writeOutput( '<li>' & x.city & ' | ' &
x.stateCode & ' | ' & x.zipCode & '</li>');
}
</cfscript>
ColdFusion 11 though current
ColdFusion 11 allows most tags to be written as cfscript.
<cfscript>
cfloop(query: geo, startrow: 1, endrow: 2) {
writeOutput( '<li>' & geo.city & ' | ' &
geo.stateCode & ' | ' & geo.zipCode & '</li>');
}
</cfscript>
With group.
<cfscript>
cfloop(query: geo, group: 'city') {
writeOutput( '<li>' & geo.city & '<ul>');
cfloop() { // no arguments, just as in the tag syntax.
https://riptutorial.com/
15
writeOutput('<li>' & geo.zipCode & '</li>');
}
writeOutput('</ul></li>');
}
</cfscript>
List
Consider this list:
<cfset foo = "one,two,three,four" />
Tag syntax
Parameters
Attribute Required Default Description
list
true
A list object. The variable must be evaluated (wrapped with
##)
index
true
The current element of the list.
<cfoutput>
<cfloop list="#foo#" index="x">
<li>#x#</li>
</cfloop>
</cfoutput>
Generated HTML
This will also have a line break between each line of HTML.
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
CFScript
Previous to ColdFusion 8
<cfscript>
for (x = 1; x LTE listLen(foo); x = x + 1) {
writeOutput("<li>" & listGetAt(foo, x) & "</li>");
https://riptutorial.com/
16
}
</cfscript>
ColdFusion 8 through current
<cfscript>
for (x = 1; x <= listLen(foo); x++) {
writeOutput("<li>" & listGetAt(foo, x) & "</li>");
}
</cfscript>
ColdFusion 9 through current
<cfscript>
for (x in foo) {
writeOutput("<li>" & x & "</li>");
}
</cfscript>
ColdFusion 11 through current
The cfscript function cfloop has no support for list.
Generated HTML
Notice that the cfscript output is all on one line.
<li>one</li><li>two</li><li>three</li><li>four</li>
Array
The ability to directly use an array object with cfloop was added in ColdFusion 8.
Consider this array;
<cfset aFoo = [
"one"
, "two"
, "three"
, "four"
] />
Tag syntax
ColdFusion 8 through current
https://riptutorial.com/
17
Using the attribute index by itself.
Parameters
Attribute Required Default Description
array
true
An array object. The variable must be evaluated (wrapped
with ##)
index
true
The current element of the array.
<cfoutput>
<cfloop array="#aFoo#" index="x">
<li>#x#</li>
</cfloop>
</cfoutput>
Generated HTML
This will also have a line break between each line of HTML.
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
ColdFusion 2016 through current
The attribute item changes the behavior of cfloop as of Coldfusion 2016.
Using the attribute item instead of or in addition to index.
Parameters
Attribute Required Default Description
array
true
An array object. The variable must be evaluated (wrapped
with ##)
item
true
The current element of the array.
index
false
The current index of the array.
<cfoutput>
<cfloop array="#aFoo#" item="x" index="y">
<li>#x# | #y#</li>
</cfloop>
</cfoutput>
https://riptutorial.com/
18
Generated HTML
This will also have a line break between each line of HTML.
<li>one | 1</li>
<li>two | 2</li>
<li>three | 3</li>
<li>four | 4</li>
CFScript
Previous to ColdFusion 8
<cfscript>
for (i = 1; x LTE arrayLen(aFoo); i = i + 1) {
writeOutput("<li>" & aFoo[i] & "</li>");
}
</cfscript>
ColdFusion 8 through current
<cfscript>
for (i = 1; i <= arrayLen(aFoo); i = i++) {
writeOutput("<li>" & aFoo[i] & "</li>");
}
</cfscript>
ColdFusion 9 through current
With the FOR IN syntax, x is the current array element, not the array index.
<cfscript>
for (x in aFoo) {
writeOutput("<li>" & x & "</li>");
}
</cfscript>
ColdFusion 11 through current
The cfscript function cfloop has no support for array.
Generated HTML
Notice that the cfscript output is all on one line.
https://riptutorial.com/
19
<li>one</li><li>two</li><li>three</li><li>four</li>
File
<cfloop list="#myFile#" index="FileItem" delimiters="#chr(10)##chr(13)#">
<cfoutput>
#FileItem#<br />
</cfoutput>
</cfloop>
Structure
Consider this structure:
<cfset stFoo = {
a = "one"
, b = "two"
, c = "three"
, d = "foue"
} />
Tag syntax
Parameters
Notice the use of the attribute item instead of index.
Attribute Required Type
Default Description
collection true
structure
A struct object. The variable must be evaluated
(wrapped with ##).
item
true
string
The current structure key,
Using Structure Functions
<cfoutput>
<cfloop collection="#stFoo#" item="x">
<li>#structFind(stFoo, x)#</li>
</cfloop>
</cfoutput>
Implicit Structure Syntax
<cfoutput>
<cfloop collection="#stFoo#" item="x">
https://riptutorial.com/
20
<li>#stFoo[x]#</li>
</cfloop>
</cfoutput>
Generated HTML
This will also have a line break between each line of HTML.
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
CFScript
With the FOR IN syntax, x is a key of the structure object.
Output the structure's keys
<cfscript>
for (x in stFoo) {
writeOutput("<li>" & x & "</li>");
}
</cfscript>
Generated HTML
<li>A</li><li>B</li><li>C</li><li>D</li>
Output the value of the structure's keys
Using Structure Functions
<cfscript>
for (x in stFoo) {
writeOutput("<li>" & structFind(stFoo, x) & "</li>");
}
</cfscript>
Implicit Structure Syntax
<cfscript>
for (x in stFoo) {
writeOutput("<li>" & stFoo[x] & "</li>");
}
</cfscript>
https://riptutorial.com/
21
ColdFusion 11 through current
The cfscript function cfloop has no support for collection.
Generated HTML
Notice that the cfscript output is all on one line.
<li>one</li><li>two</li><li>three</li><li>four</li>
Index Loop
Use the from and to attributes to specify how many iterations should occur. The (optional) step
attribute allows you to determine how big the increments will be.
<cfloop from="1" to="10" index="i" step="2">
<cfoutput>
#i#<br />
</cfoutput>
</cfloop>
Conditional Loop
You use the condition attribute to specify the condition to use.
<cfset myVar=false>
<cfloop condition="myVar eq false">
<cfoutput>
myVar = <b>#myVar#</b> (still in loop)<br />
</cfoutput>
<cfif RandRange(1,10) eq 10>
<cfset myVar="true">
</cfif>
</cfloop>
<cfoutput>
myVar = <b>#myVar#</b> (loop has finished)
</cfoutput>
Query Loop
You can loop over the results of a ColdFusion query.
<cfquery name="getMovies" datasource="Entertainment">
select top 4 movieName
from Movies
</cfquery>
<cfloop query="getMovies">
#movieName#
</cfloop>
https://riptutorial.com/
22
List Loop
You can use the (optional) delimiters attribute to specify which characters are used as separators
in the list.
<cfloop list="ColdFusion,HTML;XML" index="ListItem" delimiters=",;">
<cfoutput>
#ListItem#<br />
</cfoutput>
</cfloop>
File Loop
You can loop over a file.
<cfloop file="#myFile#" index="line">
<cfoutput>
#line#<br />
</cfoutput>
</cfloop>
COM Collection/Structure Loops
You can loop over a Structure or COM collection.
<cfset myBooks = StructNew()>
<cfset myVariable = StructInsert(myBooks,"ColdFusion","ColdFusion MX Bible")>
<cfset myVariable = StructInsert(myBooks,"HTML","HTML Visual QuickStart")>
<cfset myVariable = StructInsert(myBooks,"XML","Inside XML")>
<cfloop collection="#myBooks#" item="subject">
<cfoutput>
<b>#subject#:</b> #StructFind(myBooks,subject)#<br />
</cfoutput>
</cfloop>
Read CFLOOP How-To online: https://riptutorial.com/coldfusion/topic/3035/cfloop-how-to
https://riptutorial.com/
23
Chapter 3: cfquery
Parameters
Parameter Details
name
Value: string, Default: yes
dbtype
Value: query/hql, Default: no, Remarks: when left blank, it's a normal query
datasource Default: no, Remarks: database
params
Value: structure, Default: no, Remarks: cfscript syntax only! In cfml they are
written inside SLQ stament using <cfqueryparam />
Examples
Using cfquery within a Function
<cffunction name="getUserById" access="public" returntype="query">
<cfargument name="userId" type="numeric" required="yes" hint="The ID of the user">
<cfquery name="local.qryGetUser" datasource="DATABASE_NAME">
SELECT id,
name
FROM user
WHERE id = <cfqueryparam value="#arguments.userId#" cfsqltype="cf_sql_integer">
</cfquery>
<cfreturn local.qryGetUser>
</cffunction>
Query of Query
Function Calls
<!--- Load the user object based on the component path. --->
<cfset local.user = new com.User() />
<cfset local.allUsers = user.getAllUsers()>
<cfset local.specificUser = user.getUserIdFromQry(qry = local.allUsers, userId = 1)>
User.cfc
<cfcomponent>
<cffunction name="getAllUsers" access="public" returntype="query">
<cfquery name="local.qryGetAllUsers" datasource="DATABASE_NAME">
https://riptutorial.com/
24
SELECT id,
name
FROM user
</cfquery>
<cfreturn local.qryGetAllUsers>
</cffunction>
<cffunction name="getUserIdFromQry" access="public" returntype="query">
<cfargument name="qry" type="query" required="Yes" hint="Query to fetch from">
<cfargument name="userId" type="numeric" required="Yes" hint="The ID of the user">
<cfquery name="local.qryGetUserIdFromQry" dbtype="query">
SELECT id,
name
FROM arguments.qry
WHERE id = <cfqueryparam value="#arguments.userId#" cfsqltype="cf_sql_integer">
</cfquery>
<cfreturn local.qryGetUserIdFromQry>
</cffunction>
</component>
Read cfquery online: https://riptutorial.com/coldfusion/topic/6452/cfquery
https://riptutorial.com/
25
Chapter 4: ColdFusion Arrays
Syntax
β’
ArrayNew(dimension, isSynchronized)
Parameters
Name
Description
Dimension
Number of dimensions in new array: 1, 2, or 3
isSynchronized
When false, creates an unsynchronized array, When true, the function
returns a synchronized array.
Remarks
In a synchronized array, more than two threads cannot access the array simultaneously. Other
threads has to wait until the active thread completes its job, resulting in significant performance.
In 2016 ColdFusion release, you can use an unsynchronized array and let multiple threads access
the same array object simultaneously.
Examples
Creating Arrays
Creating arrays explicitly using ArrayNew()
Declare an array with the ArrayNew function. Specify the number of dimensions as an argument.
β’
β’
β’
ArrayNew(dimension) creates an array of 1β3 dimensions.
ColdFusion arrays expand dynamically as data is added.
ArrayNew() returns an array.
History
Introduced in ColdFusion MX 6
Declaration
CFML
https://riptutorial.com/
26
<!--- One Dimension Array--->
<cfset oneDimensionArray = ArrayNew(1)>
CFScript Note that inside a function you should use var scoping. Earlier versions of CF required
var scoping to be the first thing in a function; later versions allow it anywhere in a function.
<cfscript>
oneDimensionArray = ArrayNew(1);
public void function myFunc() {
var oneDimensionArray = ArrayNew(1);
}
</cfscript>
After creating the array, add elements by using the element indexes. The Coldfusion Array index
starts from 1:
CFML
<cfset oneDimensionArray[1] = 1>
<cfset oneDimensionArray[2] = 'one'>
<cfset oneDimensionArray[3] = '1'>
CFScript
<cfscript>
oneDimensionArray[1] = 1;
oneDimensionArray[2] = 'one';
oneDimensionArray[3] = '1';
</cfscript>
Using ArrayAppend()
You can add elements to an array using the function ArrayAppend(array, value).
<cfscript>
ArrayAppend(oneDimensionArray, 1);
ArrayAppend(oneDimensionArray, 'one');
ArrayAppend(oneDimensionArray, '1');
</cfscript>
Output the array contents using <cfdump>:
<cfdump var="#oneDimensionArray#">
Results:
https://riptutorial.com/
27
CFML
<!--- Two Dimension Array--->
<cfset twoDimensionArray = ArrayNew(2)>
<cfset twoDimensionArray[1][1] = 1>
<cfset twoDimensionArray[1][2] = 2>
<cfset twoDimensionArray[2][1] = 3>
<cfset twoDimensionArray[2][2] = 4>
CFScript
<cfscript>
twoDimensionArray = ArrayNew(2);
twoDimensionArray[1][1] = 1;
twoDimensionArray[1][2] = 2;
twoDimensionArray[2][1] = 3;
twoDimensionArray[2][2] = 4;
</cfscript>
Outputting the contents of array using <cfdump>
<cfdump var="#twoDimensionArray#">
Result:
Each element contains another Array, which will store the values.
Creating 1-D Array Implicitly
When creating an array implicitly, brackets ([]) surround the array contents with comma
separators.
<cfset oneDimensionArrayImplicit = [ 1 ,'one','1' ]>
https://riptutorial.com/
28
This statement is equivalent to the four statements used to create the above oneDimensionArray.
The result are the same when using:
<cfdump var="#oneDimensionArrayImplicit#">
Create 2-D Array Implicitly
<cfset twoDimensionArrayImplicit = [[ 1 , 2 ],[ 3 , 4 ],[ 5 , 6 ]]>
Or:
<cfset firstElement = ["1", "2"]>
<cfset secondElement= ["3", "4"]>
<cfset thirdElement = ["5", "6"]>
<cfset twoDimensionArrayImplicit = [firstElement , secondElement, thirdElement]>
Outputting the content using
<cfdump var="#twoDimensionArrayImplicit#">
Alternative Explicit Declaration
Also you can declare 1 Dimension Array as
<cfset oneDimensionArray = []>
<cfscript>
oneDimensionArray = [];
</cfscript>
This declaration is same as that of using ArrayNew(1).
But if you try declaring 2 Dimension Array as
<cfset twoDimensionArray =[][]> //Invalid CFML construct
https://riptutorial.com/
29
an error will occur while processing this request.
Following statement will process the request:
<cfset twoDimensionArray =[]>
but variable twoDimensionArray will not actually an Array within Array (or 2-Dimension Array). It
actually contains structure within Array.
<cfset twoDimensionArray =[]>
<cfset twoDimensionArray[1][1] = 1>
<cfset twoDimensionArray[1][2] = 2>
<cfset twoDimensionArray[2][1] = 3>
<cfset twoDimensionArray[2][2] = 4>
<cfdump var="#twoDimensionArray#">
Result:
Array in CFScript
<cfscript>
oneDimensionArray = ArrayNew(1);
oneDimensionArray[1] = 1;
oneDimensionArray[2] = 'one';
oneDimensionArray[3] = '1';
</cfscript>
<cfif IsDefined("oneDimensionArray")>
<cfdump var="#oneDimensionArray#">
</cfif>
Result:
Also, we can declare an one Dimension Array as:
https://riptutorial.com/
30
oneDimensionArray = [];
Alternatively, CF introduced WriteDump() from CF9 as a function equivalent to the <cfdump> tag
which can be used in <cfscript>.
<cfscript>
WriteDump(oneDimensionArray);
</cfscript>
Similarly, for 2 Dimension Array:
<cfscript>
twoDimensionArray = ArrayNew(2);
twoDimensionArray[1][1] = 1;
twoDimensionArray[1][2] = 2;
twoDimensionArray[2][1] = 3;
twoDimensionArray[2][2] = 4;
</cfscript>
<cfdump var="#twoDimensionArray#">
Result:
General information
First some general information about how arrays behave in Coldfusion as compared to other
programming languages.
β’
β’
β’
Arrays can have numeric indexes only (if you want to have a string index use structs
instead)
Arrays begin at index [1]
Arrays can have one ore more dimensions
Read ColdFusion Arrays online: https://riptutorial.com/coldfusion/topic/6896/coldfusion-arrays
https://riptutorial.com/
31
Chapter 5: Creating REST APIs in coldfusion
Introduction
REST APIs are interesting when data should be accessed from everywhere including different
languages (server and client side). That requires separation from data and processing.
Examples
Creating backend
<cfcomponent displayname="myAPI" output="false">
<cffunction name="init" access="public" output="no">
<!--- do some basic stuff --->
<cfreturn this>
</cffunction>
<cffunction name="welcome">
<cfreturn "Hello World!">
</cffunction>
</cfcomponent>
The interface
<cfscript>
api_request = GetHttpRequestData();
api = createObject("component","myAPI").init();
</cfscript>
<cfif api_request.method is 'GET'>
<cfoutput>#api.welcome()#</cfoutput>
<cfelseif api_request.method is 'POST'>
<cfheader statuscode="500" statustext="Internal Server Error" />
</cfif>
Read Creating REST APIs in coldfusion online:
https://riptutorial.com/coldfusion/topic/10698/creating-rest-apis-in-coldfusion
https://riptutorial.com/
32
Chapter 6: Database Queries
Examples
Working with databases
One of ColdFusion's strengths is how easy it is to work with databases. And of course, query
inputs can and should be parameterized.
Tag Implementation
<cfquery name="myQuery" datasource="myDatasource" result="myResult">
select firstName, lastName
from users
where lastName = <cfqueryparam value="Allaire" cfsqltype="cf_sql_varchar">
</cfquery>
CFScript Implementation
// ColdFusion 9+
var queryService = new query(name="myQuery", datasource="myDatasource");
queryService.addParam(name="lName", value="Allaire", cfsqltype="cf_sql_varchar");
var result = queryService.execute(sql="select firstName, lastName from users where lastName =
:lName");
var myQuery = result.getResult();
var myResult = result.getPrefix();
// ColdFusion 11+
var queryParams = {lName = {value="Allaire", cfsqltype="cf_sql_varchar"}};
var queryOptions = {datasource="myDatasource", result="myResult"};
var myQuery = queryExecute("select firstName, lastName from users", queryParams,
queryOptions);
Inserting values is just as easy:
queryExecute("
insert into user( firstname, lastname )
values( :firstname, :lastname )
",{
firstname: { cfsqltype: "cf_sql_varchar", value: "Dwayne" }
,lastname: { cfsqltype: "cf_sql_varchar", value: "Camacho" }
},{
result: "local.insertResult"
});
return local.insertResult.generated_key;
Basic Example
Database connections are set up using the CF Administrator tool. See Database Connections for
how to connect a datasource.
https://riptutorial.com/
33
To execute queries all you need is the <cfquery> tag. The <cfquery> tag connects to and opens the
database for you, all you need to do is supply it with the name of the datasource.
<cfquery name="Movies" datasource="Entertainment">
SELECT title
FROM Movies
</cfquery>
To display the query results:
<cfoutput query="Movies">
#title#<BR>
</cfoutput>
Authentication
Many database configurations require authentication (in the form of a username and password)
before you can query the database. You can supply these using the username and password
attributes.
Note: the username and password can also be configured against the datasource in the
ColdFusion Administrator. Supplying these details in your query overrides the username and
password in the ColdFusion Administrator.
<cfquery datasource="Entertainment" username="webuser" password="letmein">
select *
from Movies
</cfquery>
Cached Queries
A cached query is a query that has its results stored in the server's memory. The results are
stored when the query is first run. From then on, whenever that query is requested again,
ColdFusion will retrieve the results from memory.
You can cache a query using the cachedAfter attribute. If the query was last run after the supplied
date, cached data is used. Otherwise the query is re-run.
<cfquery datasource="Entertainment" cachedAfter="July 20, 2016">
select *
from Movies
</cfquery>
In order for the cache to be used, and multiple calls to the database be avoided the current query
must use the same SQL statement, data source, query name, user name, and password as the
cached query used. This includes whitespace in the query.
As such the following queries create different caches, even though the trimmed characters are the
same and the query results are identical:
https://riptutorial.com/
34
<cfquery datasource="Entertainment" cachedAfter="July 20, 2016">
select *
from Movies
<cfif false>
where 1 = 1
</cfif>
<cfif true>
where 1 = 1
</cfif>
</cfquery>
<cfquery datasource="Entertainment" cachedAfter="July 20, 2016">
select *
from Movies
<cfif true>
where 1 = 1
</cfif>
<cfif false>
where 1 = 1
</cfif>
</cfquery>
Limiting the Number of Records Returned
You can limit the number of rows to be returned by using the maxrows attribute.
<cfquery datasource="Entertainment" maxrows="50">
select *
from Movies
</cfquery>
Timeouts
You can set a timeout limit using the timeout attribute. This can be useful in preventing requests
running far longer than they should and impacting on the whole application as a result.
The timeout attribute sets the maximum number of seconds that each action of a query is allowed
to execute before returning an error.
<cfquery datasource="Entertainment" timeout="30">
select *
from Movies
</cfquery>
Read Database Queries online: https://riptutorial.com/coldfusion/topic/4582/database-queries
https://riptutorial.com/
35
Chapter 7: How to invoke a private method
dynamically
Remarks
Use of <cfinvoke> or invoke() should be faster than evaluate()
Examples
CFML
<cfinvoke method="#somePrivateMethodName#">
<cfinvokeargument name="argument1" value="one">
</cfinvoke>
CFSCRIPT (CF10+)
invoke("", somePrivateMethodName, {argument1='one'});
Read How to invoke a private method dynamically online:
https://riptutorial.com/coldfusion/topic/6110/how-to-invoke-a-private-method-dynamically
https://riptutorial.com/
36
Chapter 8: Scopes in Coldfusion
Introduction
A scope is "the range in which a variable can be referenced". ColdFusion knows β as well as
most other programming and script languages β several scopes. The following text deals with
these types and trys to bring clarity about them, their differences and their characteristics.
Examples
Request Scopes
request
variables
form
url
cgi
Global Scopes
Server
Application
Session
Components and functions
variables
this
local
arguments
Custom tags
attributes
thisTag
caller
https://riptutorial.com/
37
Common scopes
Mostly you're probably working with these scopes:
β’
β’
β’
β’
β’
β’
Variables scopeis the scope where all variables are assigned to when nothing else is
intentionally declared (like the window scope in JavaScript).
Form scopeWhen you send a form to your server, all the form fields which can be identified
(by setting the name/id property) are accessible in this scope for further server-side
processing.
URL scopeAll url query params are stored in that scope
this scopeInside a component the this refers to the component itself
local scopeVariables declared inside a function using the local statement are encapsulated
and only accessible inside that specific function (this is made to avoid pollution of other
sopes)
Arguments scopeArguments passed to a function inside a component declared by the
cfargument tag are accessible with that scope
Overview
β’
Components and functions
β
β
β
β
variables
this
local
arguments
β’
Custom tags
β
β
β
attributes
thisTag
caller
β’
Global Scopes
β
β
β
Server
Application
Session
β’
Request Scopes
β
β
β
β
β
request
variables
form
url
cgi
Read Scopes in Coldfusion online: https://riptutorial.com/coldfusion/topic/7864/scopes-in-
coldfusion
https://riptutorial.com/
38
Chapter 9: Variables
Parameters
Attribute Description
name
(Required) Name of the parameter/variable.
default
(Optional) Value to set parameter to if it does not exist.
max
min
(Optional) The maximum valid value; used only for range validation.
(Optional) The minimum valid value; used only for range validation.
pattern
(Optional) A JavaScript regular expression that the parameter must match; used
only for regex or regular_expression validation.
type
(Optional) The valid format for the data.
Examples
Using cfset
You can set a ColdFusion variable using the <cfset> tag. To output the variable, you need to
surround the variable name with hash # symbols and enclose it within <cfoutput> tags.
<cfset variablename="World!">
<cfoutput>
Hello #variablename#
</cfoutput>
Using cfparam
The <cfparam> tag creates a variable if it does not already exist. You can assign a default value
using the default attribute. This can be used if you want to create a variable, but don't want to
overwrite it if it has been previously created elsewhere.
Here the variable hasn't been set previously, so it will be assigned with the <cfparam> tag.
<cfparam name="firstName" default="Justin">
<cfoutput>
Hello #firstName#
</cfoutput>
Here the variable has already been assigned using the <cfset> tag, so this value will override the
default value in the <cfparam> tag.
https://riptutorial.com/
39
<cfset firstname="Justin">
<cfparam name="firstName" default="Barney">
<cfoutput>
Hello #firstName#
</cfoutput>
Checking if a Variable Exists
You can check if a variable has been defined in a scope by using ColdFusion's built in
StructKeyExists() function. This can be used inside a <cfif> tag to prevent error messages in the
event you attempt to refer to a variable that does not exist. You can also use this function to
determine whether a user has performed a certain action or not. The syntax for the function is
StructKeyExists(structure, "key")
The following example checks if the variable firstName exists in the variables scope.
<cfif StructKeyExists(variables, "firstName")>
Hello #variables.firstname#!
<cfelse>
Hello stranger!
</cfif>
Alternatively, you may use the function:
isDefined("scopeName.varName")
To avoid ambiguity, it is recommended to declare the scope. For example, If you have a variable
in the scope test
<cfset test.name = "Tracy" />
and you test for name in the global scope, you will get a result of true.
isDefined("name") <!--- true --->
isDefined("x.name") <!--- false--->
isDefined("test.name") <!--- true --->
Setting a variable scope
It is a common practice to set application variables to an object scope. This keeps them easy to
identify and distinguish from variables in other scopes.
The Variables scope in a CFC is private to the CFC. When you set variables in this scope, they
cannot be seen by pages that invoke the CFC.
<cfparam name="variables.firstName" default="Timmy">
<cfset variables.firstName="Justin">
https://riptutorial.com/
40
Scopes shared with the calling page include: Form, URL, Request, CGI, Cookie, Client, Session,
Application, Server, and Flash. Variables in these scopes are also available to all pages that are
included by a CFC.
CFC:
<cfset url.sessionId="23b5ly17">
<cfinclude template="check_session.cfm">
check_session.cfm
<cfif url.sessionId eq "23b5ly17">
<p>Welcome back!</p>
</cfif>
Read Variables online: https://riptutorial.com/coldfusion/topic/4904/variables
https://riptutorial.com/
41
Chapter 10: Working with RegExp Replace
callbacks
Introduction
If you want more than a simple string replacement with common regular expressions you certainly
run into trouble and hit the wall when discovering the limits of the regex functions Coldfusion has.
There is no build-in function like php's preg_replace_callback.
Parameters
Parameter Details
re
str
The regular expression
The string which should be applyed the the regex
callback
The function where the captured grouped will be passed in if a match was
found. There the matches can be processed
Remarks
Because Coldfusion itself does not offer what we want, we make recourse to the variety of Java,
which is β as we all know β on top of Coldfusion. Java offers us java.util.regex.Pattern.
So here is what we actually do:
1.
2.
3.
Invoke the Compile method from the Pattern Class object and passing the regex pattern to it
(which probably deposits the regex pattern for later use).
Invoke the Matcher method on what the Compile method returned and passing the string
where the pattern should be executed.
Test if matching was successfull by invoking the find method on what the Matcher method
returned.
If matcher.find() returns true, we could say "That's it", but there is one little thing we have to
consider: Java's Pattern object stores the groups and gives us access via another function, which
is not always the best way for further processing and not that consistent regarding how other
programming languages handle this case. Therefore we loop over matcher.group() so that we can
pass an array containing the captured groups to the callback function. And now we can say:
"That's it!"
Examples
https://riptutorial.com/
42
User defined REReplaceCallback function
function REReplaceCallback(re,str,callback) {
/*
Thanks to Ben Nadel
"Learning ColdFusion 8: REMatch() For Regular Expression Matching"
from 2007-06-13
https://www.bennadel.com/blog/769-learning-coldfusion-8-rematch-for-regular-
expression-matching.htm
*/
pattern = CreateObject("java","java.util.regex.Pattern").Compile(Arguments.re);
matcher = pattern.Matcher(Arguments.str);
if(matcher.find()) {
groups = [];
for(var i = 1; i lte matcher.groupCount(); i++) {
ArrayAppend(groups,matcher.group(Val(i)));
}
return Arguments.callback(groups);
}
else {
return Arguments.callback(false);
}
}
Using REReplaceCallback function
REReplaceCallback('YOUR REGEX GOES HERE','AND YOUR STRING HERE',function(groups) {
//now you can access the 'groups' array containing all the captured groups
return result; //return whatever you've processed inside
});
Read Working with RegExp Replace callbacks online:
https://riptutorial.com/coldfusion/topic/10655/working-with-regexp-replace-callbacks
https://riptutorial.com/
43
Credits
S.
No
1
2
3
4
5
6
7
8
9
Chapters
Contributors
Getting started with
coldfusion
Adam Tuttle, Adrian J. Moreno, Community, Justin Duhaime,
mhatch, RamenChef, shaedrich, Steven Benjamin,
user3071284, William Giles
CFLOOP How-To
Adrian J. Moreno, Bonanza, mhatch, RRK
cfquery
Bubblesphere, shaedrich
ColdFusion Arrays
4444, Justin Duhaime, mhatch, Mishra Shreyanshu, shaedrich
Creating REST APIs
in coldfusion
shaedrich
Database Queries
Adam Tuttle, Leigh, mhatch, nosilleg, shaedrich, user3071284
How to invoke a
private method
dynamically
Henry
Scopes in Coldfusion
James A Mohler, shaedrich
Variables
mhatch
10
Working with
RegExp Replace
callbacks
shaedrich
https://riptutorial.com/
44
|