Skip to content

Instantly share code, notes, and snippets.


Block or report user

Report or block learncfinaweek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
learncfinaweek / gist:4121071
Created Nov 20, 2012
Decision Making and Scopes - Decision Making
View gist:4121071

An important part of any program is the ability to make decisions based upon a set of conditions. This is aptly named 'conditional logic'. Unless you are writing a static set of HTML pages, you will almost certainly need to evaluate conditions. In conditional logic, all conditions tested must evaluate to a Boolean, either true or false. As you learned in the variables section of this training, ColdFusion is a dynamically typed language. This does not mean that ColdFusion is not typed, but rather that ColdFusion can switch from type to type dynamically while the application is executing. This is a great feature when using conditional logic as you do not need to explicitly define the Boolean such as myVar == true, but for simple variables you can allow ColdFusion to evaluate the value of the variable and convert it dynamically to a Boolean value. Keep this in mind, and we will revisit this in a bit.

ColdFusion has both if/then/else tags

learncfinaweek / gist:4121080
Created Nov 20, 2012
Decision Making and Scopes - Scopes
View gist:4121080

ColdFusion groups variables together in scopes, or a range in which a variable can be accessed. Think of a scope as a bucket of memory that can store variables. Each scope has its own purpose, and each scope has its own lifecycle.

The following table shows major scopes available in a running ColdFusion application:

  • Variables: Default scope available in ColdFusion templates. Variables are available only during the execution of the template.
learncfinaweek / gist:4121092
Created Nov 20, 2012
Decision Making and Scopes - Hands On 3
View gist:4121092
In this hands on, you are going to add some conditional logic to the site as well as create a form post.
<strong>Tags Used</strong>: <a href="" target="_new">&lt;cfif></a>, <a href="" target="_new">&lt;cfparam> </a>
Open up the <span class="code">/www/contact.cfm</span> file in your code editor.
learncfinaweek / gist:4121096
Created Nov 20, 2012
Decision Making and Scopes - Hands On 4
View gist:4121096

In this hands on, you are going to validate the form data that was submitted and output any problems that might have occurred. We will access data from the form scope.

Tags Used: <cfset>, <cfif>

Functions Used: len

learncfinaweek / gist:4121101
Created Nov 20, 2012
Decision Making and Scopes - Hands On 5
View gist:4121101

In this hands on, you are going to update our code to provide a better user experience to your users as well as improve the form validation.

Tags Used: <cfparam>, <cfoutout>

Functions Used: len, trim

learncfinaweek / gist:4121103
Created Nov 20, 2012
Decision Making and Scopes - Hands On 6
View gist:4121103

In this hands on, we are going to refactor our code and take out any unnecessary logic we might have.

Tags Used: <cfif>, <cfelse>

  1. Open up the /www/contact.cfm file in your code editor and locate the <cfif> statement that checks the form.contactname variable. Remove the eq 0 part of the expression; as any number greater than 0 is treated as true, and the number 0 is treated as false, we do not need this additional part of the <cfif> statement. Because we only want to run the code when there is NO value passed we must negate the value by putting the word NOT before
View gist:4121109

Looping is employed by programming languages to repeat a behavior defined by a section of code either while a condition is maintained true (conditional looping), or a certain number of times (iterative looping). As with other programming languages, ColdFusion allows you to perform both iterative and conditional looping.

ColdFusion uses the cfloop tag to enable looping in tag-based syntax. cfloop permits you to loop over a variable such as a structure or array, loop while a condition remains true, or loop for a given iteration. ColdFusion permits looping in cfscript using for loops and do while loops.

Tag-based Looping

learncfinaweek / gist:4121113
Created Nov 20, 2012
Looping - Hands On 7
View gist:4121113

In this hands on, we will perform some simple looping using a list and output it to the page.

Tags Used: <cfset>, <cfloop>, <cfoutput>

  1. Open up the /www/resume.cfm file in your code editor.
learncfinaweek / gist:4121117
Created Nov 20, 2012
Looping - Hands On 8
View gist:4121117
learncfinaweek / gist:4121125
Created Nov 20, 2012
Data Handling - Databases
View gist:4121125

One of the key parts of any application is its ability to do CRUD (Create, Read, Update, and Delete) operations. ColdFusion has the ability to read a variety of data sources with minimal effort; there is built in support for over ten different databases. Among the supported databases, you will find MS SQL, MySql, Oracle, DB2, and Sybase. There are slight sql syntax differences when interacting with the database; however, the same code can be used against different databases without any changes.

Note: This chapter will not teach you how to write sql. However, it will show you how to take the sql skills you have and incorporate them into your code. Alternatively, if you are using ColdFusion Builder, you can use the query builder to assist you with query creation.

Query Basics

You can’t perform that action at this time.