Skip to content

Instantly share code, notes, and snippets.

learncfinaweek

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
learncfinaweek / gist:4121048
Created Nov 20, 2012
Basics - Script vs Tag
View gist:4121048

ColdFusion has been designed to allow the use of ColdFusion tags and ColdFusion script. Functionally, both will be interpreted equally and will achieve the same result. The use of ColdFusion Tags and ColdFusion Script is up to personal or team preference. One or two ColdFusion operations are currently Tag only, as of this tutorial, but these will be made available in ColdFusion script in future releases.

Some developers write all ColdFusion code in Tags. Some developers write all ColdFusion code in Script. Some write the view portions of their ColdFusion code in Tags and the business layer portion in Script. As long as you stay consistent, all approaches are valid. The overarching rule should be legibility and consistency.

Let's look at some statements and compare the differences:

@learncfinaweek
learncfinaweek / gist:4120988
Created Nov 20, 2012
Setup - Installing MySQL
View gist:4120988

ColdFusion has the ability to communicate with a number of different databases, which will be covered later on in this course; for the sample application we will be working on throughout the course, we will be using MySQL. If you already have MySQL 4 or 5 already installed, you can proceed to the 'Install Sample Files' section. If not, follow the steps below:

Windows

  1. Open up a browser and go to: http://dev.mysql.com/downloads/mysql/
@learncfinaweek
learncfinaweek / gist:4121006
Created Nov 20, 2012
Basics - What is ColdFusion?
View gist:4121006

ColdFusion is a rapid development platform for building modern web applications. ColdFusion is designed to be expressive and powerful. The expressive characteristic allows you to perform programming tasks at a higher level than most other languages. The powerful characteristic gives you integration with functionality important to web applications like database access, MS Exchange access, PDF form creation and more.

The ColdFusion platform is built on Java and uses the Apache Tomcat J2EE container. While you have full access to Java and Tomcat, you need not worry about these details. You'll interact with ColdFusion and the user friendly ColdFusion Mark-up Language (CFML) to write your programs. Your ColdFusion files will use the file extension '.cfc' for objects and '.cfm' for pages. CFML requires much less ceremony and infrastructure than typical java while offering a significantly faster development experience than Java.

After taking this CF in a Week series, you'll have the basics n

@learncfinaweek
learncfinaweek / gist:4121092
Created Nov 20, 2012
Decision Making and Scopes - Hands On 3
View gist:4121092
<p>
In this hands on, you are going to add some conditional logic to the site as well as create a form post.
</p>
<p>
<strong>Tags Used</strong>: <a href="http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fe8.html" target="_new">&lt;cfif></a>, <a href="http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7faf.html" target="_new">&lt;cfparam> </a>
</p>
<p>
<ol>
<li>
Open up the <span class="code">/www/contact.cfm</span> file in your code editor.
@learncfinaweek
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
@learncfinaweek
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
learncfinaweek / gist:4121227
Created Nov 20, 2012
Code Reuse - Custom Tags
View gist:4121227

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>

View gist:4121012

In our last Section, we talked about variables, data, and how to transport data around in your application. Different data types serve different purposes.

Strings/Numbers

Is Simple: Yes

View gist:4121015

In our previous sections we talked about the importance of adding context into your programs. You’ll find you will spend much more time reading programs for the purposes of debugging and enhancing, than you spend writing the program. So take care to write your programs in such a way the program can be read and understood as easily as possible.

Context is important because our programs express a problem to a computer using a kind of shorthand, in our case ColdFusion programming code. The computer doesn’t much care about the amount of context in the application, as long as the instructions (code) are all properly formed. The program is good enough for the computer if it works well. But this doesn’t necessarily mean the program is good enough for a human. Programs that are good for humans can be efficiently understood, debugged and enhanced by another programer.

One way to add context is to use descriptive variable names.

View gist:4121052

In the first part of this hands on we are going to convert some pages to .cfm pages. We will then add some variables and output them to the user. Finally, we will add a comment to our code.

Tags Used: <cfset>, <cfoutput>

  1. Rename the /www/index.html file to index.cfm.
You can’t perform that action at this time.