Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
ColdFusion 9 Developer Tutorial

You're reading from   ColdFusion 9 Developer Tutorial Create robust professional web applications with ColdFusion

Arrow left icon
Product type Paperback
Published in Jul 2010
Publisher Packt
ISBN-13 9781849690249
Length 388 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
John Farrar John Farrar
Author Profile Icon John Farrar
John Farrar
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

ColdFusion 9 Developer Tutorial
Credits
About the Author
About the Reviewers
1. Preface
1. Web Pages—Static to Dynamic 2. Basic CFCs and Database Interaction FREE CHAPTER 3. Power CFCs and Web Forms 4. ORM Database Interaction 5. Application, Session, and Request Scope 6. Authentication and Permissions 7. CFScript 8. CF AJAX User Interface 9. CF AJAX Forms 10. CF AJAX Programming 11. Introduction to Custom Tags 12. ColdFusion Powered Views 13. Control Logic Processing 14. Guide to Unit Testing Beyond this Book Tools and Resources 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:

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image