Browse files

fixed some markdown formatting issues with other parsers (self closin…

…g a tags and proper spacing before links))
  • Loading branch information...
1 parent 64ffeca commit b1701e6726ed0a3880b268891f093e521de363fe @bittersweetryan bittersweetryan committed Jan 19, 2012
Showing with 32 additions and 21 deletions.
  1. +32 −21 cfml100mins.markdown
@@ -28,9 +28,9 @@ CFML tag syntax resembles HTML and the CFML script syntax, CFScript, resembles E
And you want to learn CFML so here goes!
-<a name="syntax" />
+<a name="syntax" >
## 1. Syntax
There are two ways to write CFML code. You can use tag or script syntax. For the examples, please focus on one or the other so this tutorial is not confusing.
CFML includes a set of instructions you use in pages. You will write one or more instructions in a file then run the file through a CFML engine. Three CFML instructions we will use in this tutorial are ```CFSET```, ```CFOUTPUT```, and ```CFDUMP```. ```CFSET``` is used to create a variable and assign it a value. Also ```CFSET``` is used to call methods. ```CFOUTPUT``` displays a variable's value. ```CFDUMP``` is used to display the contents of simple and complex variables, objects, components, user-defined functions, and other elements.
@@ -117,9 +117,10 @@ end
s =
puts s.hello
-<a name="variables" />
-## 2. Variables
+<a name="variables" >
+## 2. Variables
Everything needs a name so we can refer to it. A variable, like in math, is just a name for a piece of data. In CFML, variables are very flexible and can be changed at any time. Variables are assigned using a single equals sign ```=``` where the **right** side of the equals sign is evaluated first, then the value is assigned to the variable named on the **left** side of the equals.
Go into a CFML file, enter in these example instructions, and observe the output that CFML gives you back:
@@ -192,9 +193,9 @@ writeOutput("b = #b#<br/>");
*The first few lines in the first example are simple if you've done any programming language before, but the last few get interesting when combining strings and numbers. The code looks a little messy since after each instruction we output a variable.
-<a name="cfc" />
+<a name="cfc" >
## 3. Components, Methods, and Parameters
### Components (aka Objects or Classes)
In CFML, a ColdFusion component (CFC) is a file that contains data and methods. Components are the building blocks for objects in CFML. Objects know information, called "attributes", and can do actions, called "methods". In ColdFusion the ```cffunction``` tag is used to define methods within a tag-based CFC. In a script-based CFC, you use the ```function``` keyword to define a method.
@@ -324,9 +325,10 @@ component name = "PersonalChef" {
-<a name="strings" />
-## 4. Strings
+<a name="strings" >
+## 4. Strings
In CFML a string is defined as a quote ( **'** or **"** ) followed by zero or more letters, numbers, or symbols and followed by another quote ( **'** or **"** ). Some simple strings would be **hello** or **This sentence is a string!**. Strings can be anything from "", the empty string, to really long sets of text. This whole tutorial, for instance, is stored in a string. Strings have a few important instructions that we'll use.
### Len
@@ -469,9 +471,10 @@ message = "Happy #today#!";
If you compare the output you'll see the second example gives the exact same results. The code itself is a little more compact and, personally, I find it much easier to read.
Basically *interpolating* means evaluate the code inside this ```#``` wrapper and put it into the string.
-<a name="numbers" />
-## 5. Numbers
+<a name="numbers" >
+## 5. Numbers
There are two basic kinds of numbers in CFML: integers (whole numbers) and real (numbers with a decimal point). For our workshop, we'll only be dealing with integers. You can use normal math operations with integers including ```+```, ```-```, ```/``` and ```*```. The ```++``` operator can be used to increment a number. It is also the only one we will use to control a loop. We will talk more about Conditional Looping in section 9. Try out this example for the ```++``` operator:
#### Tag Syntax
@@ -554,9 +557,10 @@ while (loop < 5) {
-<a name="recordsets" />
-## 6. Recordsets
+<a name="recordsets" >
+## 6. Recordsets
A query is a request to a database. It returns ```query object``` containing a **recordset** and other information. The query can ask for information from the database, write new data to the database, update existing information in the database, or delete records from the database. ```cfquery``` passes SQL statements to the ```datasource```. The ```datasource``` is set in the ColdFusion administrator.
#### Tag Syntax
@@ -596,8 +600,10 @@ There are #GetBreakfastItems.Quantity# #GetBreakfastItems.Item# in the pantry<br
While it's not strictly necessary to prepend the recordset name before the column name inside the ```<cfoutput>```, it's strongly recommended that you do in order to prevent referencing the wrong variable scope.
-<a name="sqlinjection" />
+<a name="sqlinjection" >
#### Prevent SQL Injection
In ColdFuison it is easy to make your queries to the database dynamic by passing in variables, however a ColdFusion developer must make their sure their queries are not vulenrable to malicious code. This type of code, known as SQL Injection, allows a hacker to run queries on your database by passing code to your query through a url or form value. It is imperitive that queries are protected using a tag called cfqueryparam. **It is never a good idea to leave query variables unprotected**
For a single value the cfqueryparam tag is used like so:
@@ -784,8 +790,9 @@ There are some other ways to loop over queries, and one that comes in handy for
-<a name="arrays" />
+<a name="arrays" >
## 7. Arrays
Often we need to organize a group and put them into a *collection*. There are two main types of collections: **arrays** and **structures**.
@@ -960,8 +967,9 @@ Matt
-<a name="structures" />
+<a name="structures" >
## 8. Structures
A structure is a *collection of data* where each element of data is addressed by a name. As an analogy, think about a classroom of children. Under ideal circumstances, each student has a name and can be found by using that name. We might look in a science classroom for a child named Joey and that would result in finding an actual student. We could write this like ```science["Joey"]``` which could be read as "look in the collection named 'science' and find the thing named 'Joey'".
@@ -1042,15 +1050,17 @@ The last chunk of the example used ```StructSort``` to get the sorted array "stu
While that last part probably seemed complicated, it's just to illustrate that structures are unordered.
-<a name="conditionals" />
+<a name="conditionals" >
## 9. Conditionals
Conditional statements evaluate to ```true``` or ```false``` only. The most common conditional operators are ```==``` (equal), ```!=``` (not equal), ```>``` (greater than), ```>=``` (greater than or equal to), ```<``` (less than), and ```<=``` (less than or equal to). You can also define the operators as abbreviations: ```EQ```, ```NEQ```, ```GT```, ```GTE```, ```LT```, and ```LTE```. You can **only** use the abbreviations when using tags.
Some instructions return a ```true``` or ```false```, so they're used in conditional statements, for example, "IsArray" which is "true" only when the variable is an "array". Structures have an instruction named ```StructKeyExists``` which returns "true" if a key is present in a structure.
-<a name="if" />
-### 9. 1. If, Else If, & Else
+<a name="if" >
+### 9. 1. If, Else If, & Else
Why do we have conditional statements? Most often its to control conditional instructions, especially ```if``` / ```else if``` / ```else``` structures. Lets write an example by adding a method to our **PersonalChef** class:
#### Tag Syntax
@@ -1120,9 +1130,9 @@ An ```if``` block has:
Only *one* section of the ```if``` / ```else if``` / ```else``` structure can have its instructions run. If the ```if``` is ```true```, for instance, CFML will never look at the ```else if```. Once one block executes, that’s it.
-<a name="loop" />
+<a name="loop" >
### 9. 2. Looping
Another time we use conditional statements is when we want to repeat a set of instructions. Try out this simple example by adding it to your _PersonalChef.cfc_:
#### Tag Syntax
@@ -1177,8 +1187,9 @@ the difference between ```=``` and ```==```.
* ```==``` is a *question*. It means "is the thing on the right equal to
the thing on the left" (or its *asking* not *telling*.)
-<a name="nothingness" />
+<a name="nothingness">
## 10. Nothingness & Null
What is *nothingness*? Is there nothingness only in outer space? Really, when we think of *nothing* isn't it just the absence of something? Ok, that's too much philosophy

0 comments on commit b1701e6

Please sign in to comment.