Skip to content

Instantly share code, notes, and snippets.

@learncfinaweek
learncfinaweek / gist:4121227
Created November 20, 2012 21:20
Code Reuse - Custom Tags

For displaying code on the front end, another option is to use a custom tag. Custom tags live in their own directory and are prefixed with "cf_". Putting a custom tag on a cfml page will execute the code contained in the tag as if it had been included on the page itself. Start by creating a new .cfm file to house our custom tag. Let's call it greeting.cfm. First, check the executionMode of the tag. If the executionMode is "start", that means that the tag is being opened. If executionMode is "end", that means that the tag is being closed. This can be checked by setting up an if statement like so:

<cfif thisTag.executionMode EQ "start">

<!--- Code to execute when the tag is being opened --->

<cfelse>

@learncfinaweek
learncfinaweek / gist:4121071
Created November 20, 2012 21:00
Decision Making and Scopes - Decision Making

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
learncfinaweek / gist:4121096
Created November 20, 2012 21:02
Decision Making and Scopes - Hands On 4

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
learncfinaweek / gist:4121101
Created November 20, 2012 21:03
Decision Making and Scopes - Hands On 5

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
learncfinaweek / gist:4121125
Created November 20, 2012 21:06
Data Handling - Databases

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

@learncfinaweek
learncfinaweek / gist:4121129
Created November 20, 2012 21:07
Data Handling - json

JSON or, JavaScript Object Notation, is a simple way for applications to share data. It is commonly used to send data from a server to a browser client, but it can be used for much more. It closely resembles XML without the markup or, more accurately, a struct of structs. Creating JSON data in ColdFusion is just about as easy as setting a variable.

Create JSON String

To create JSON, you first need to start with a structure. For example:

@learncfinaweek
learncfinaweek / gist:4121245
Created November 20, 2012 21:23
Code Reuse - Hands On 14

In this hands on, we will create a custom tag that will handle the display of the header and footer.

Tags Used: <cfif>, <cfelse>, <cfset>, <cfimport>

  1. Create a folder called customTags in the /www/ folder.
@learncfinaweek
learncfinaweek / gist:4121267
Created November 20, 2012 21:25
Application.cfc - Hands On 16
@learncfinaweek
learncfinaweek / gist:4121117
Created November 20, 2012 21:05
Looping - Hands On 8
@learncfinaweek
learncfinaweek / gist:4121145
Created November 20, 2012 21:09
Data Handling - Hands On 10