Book Image

ColdFusion 9 Developer Tutorial

By : John Farrar
Book Image

ColdFusion 9 Developer Tutorial

By: John Farrar

Overview of this book

Adobe ColdFusion is an application server, renowned for rapid development of dynamic websites, with a straightforward language (CFML), powerful methods for packaging and reusing your code, and AJAX support that will get developers deep into powerful web applications quickly. However, developing rich and robust web applications can be a real challenge as it involves multiple processes.With this practical guide, you will learn how to build professional ColdFusion applications. Packed with example code, and written in a friendly, easy-to-read style, this book is just what you need if you are serious about ColdFusion.This book will give you clear, concise, and practical guidance to take you from the basics of ColdFusion 9 to the skills that will make you a ColdFusion developer to be reckoned with. It also covers the new features of ColdFusion 9 like ORM Database Interaction and CF Builder.ColdFusion expert John Farrar will teach you the basics of ColdFusion programming, application architecture, and object reuse, before showing you a range of topics including AJAX library integration, RESTful Web Services, PDF creation and manipulation, and dynamically generated presentation files that will make you the toast of your ColdFusion developer town.This book digs deep with the basics, with real-world examples of the how and whys, to get more done faster with ColdFusion 9.
Table of Contents (22 chapters)
ColdFusion 9 Developer Tutorial
Credits
About the Author
About the Reviewers
Preface
Index

Understanding structures


Now we are going to shift to understanding the concept of structures. Structures are one of the first of the most powerful variables we will be looking at in this book. This is an example of how structures work. Don't use it for more than an illustration. Structures are like folders and files on a computer file system. Folders can be empty or contain multiple files or nested folders. The files can contain different types of content.

Structures in ColdFusion work along the same concepts. Your structures can be empty or contain both additional nested structures and/or variables holding data.

There are two types of structures that we will initially look at: CGI and URL.

CGI variables

Let us look at our first built-in structure type. It is called CGI. We will also take a look at the most commonly used debugging tool for many developers. CGI is a collection of variables that gives details about things ranging from the current request and the browser of the requesting user, to information about the current running server. Although it doesn't tell us everything, it does provide good information that we may visit over and over again. All structures start with a base structure element. It should be no surprise that the CGI structure starts with cgi followed by a dot ( . ) with the structure variable name.

cgi.structure_item_name

Let's look at an easy way to see what is available. If you do this yourself, you can scroll through and see how much information it offers. The following is the simple code. You will also note that the pound symbols surround the variable name. This is required for functions to work right. Don't worry if it seems odd at first; you will pick it up pretty fast even if you don't get it at first glance.

<!--- Example: 1_7.cfm --->
<!--- Processing --->
<!--- Content --->
<cfdump var="#cgi#">

The <cfdump> tag in ColdFusion takes any complex data type and creates a grid or nested grid if there is nested structure to display the contents of the variable. Dump allows us to see the state of a variable structure at a fixed point in the processing cycle of our web pages. There are options to not expand and also to give a label to the dump for occasions when we may put more than one dump on a page during our programming cycle. It should be noted that we don't want to use this type of function on final production code because for some reason users always think that this means the system has crashed. There is also a possibility to expose information that we did not want to make public. Look at the end of the page; we can see the server port, if the port was secure, and many other details with this dump:

You will see everything from server variables to the remote address of the requesting user. If you were to access these directly in the code you would do it like this. You will notice that the structure cgi contains a good number of variables. In this case, there is no nested structure but only variables. This makes for a better introduction to structures:

<!--- Example: 1_8.cfm --->
<!--- Processing --->
<cfscript>
requestedDomain = cgi.server_name;
isSecure = cgi.server_port_secure;
</cfscript>
<!--- Content --->
<cfoutput>
The requested domain was #requestedDomain#.<br />
Was the current request secure (0 = No/1 = Yes) ? #isSecure# <br />
</cfoutput>

The following screenshot shows us that this request was not secure: