Programmer's Heaven

Programmer's Heaven
Picture

Monday, June 7, 2010

Cold Fusion - Array and Structures

COLDFUSION MARKUP LANGUAGE (CFML) is ColdFusions own set of tags that makes up the bulk of the dynamic functionality found on ColdFusion pages. CFML has two different parts that make ColdFusion work: tags and functions. In this chapter we cover a whole bunch of CFML tags and also some basic functions. Chapter 4 shows you how to use some of the more advanced functions and teaches you about variable scopes and different data types.


Tags are used to carry out operations, such as looping over Recordsets, uploading files to a web server by way of a web form, dumping the contents of a variable to the screen for debugging, and grabbing the contents of a remote page on the Web. Functions within ColdFusion are used to manipulate data or perform calculations. For example, ColdFusion has a function called #ArrayAvg()#, which calculates the average of the numeric values within an array. You often must use tags and functions together to build a completely functional site.

HTML and ColdFusion tags can exist together within a document that is requested from a web server. All ColdFusion tags start with


Whenever using ColdFusion tags within a document, you must save it as a.cfmfile for it to be recognized and interpreted by the ColdFusion server.


In text strings, all text is considered literal unless it is within a set of pound/hash (#) signs.


ColdFusion elements (the opening and closing tags, and everything in between) are called blocks. For example, if you were using aelement in your code, it would be called theblock.


To add comments inside ColdFusion tags, you must use CFML comment delimiters:. Notice that these are similar to HTML comments, but have three dashes instead of two. If you use HTML comments inside your CFML, they will not be ignored by the ColdFusion server as expected, and you will either get errors or will dynamically create HTML comments. Also, CFML comments will not send text back to the users browser like HTML comments do.


Array and Structures:


Structures are everywhere in the ColdFusion world. As of ColdFusion 4.5, form, application, session, server, request, and URL variables are stored in structures. Allaire Spectra makes extensive use of structures and associative arrays. But what are they and why should you care?


1.Structures and Their Benefits
2.Structures and Arrays: A Dynamic Duo


3.Extracting Data from Arrays and Structures
4.Nested Arrays


Simply, structures are used to refer to related values as a unit rather than individually. They provide a way to group variables logically. Also, with built-in structure related functions and the ability to nest functions and arrays, variables become much more powerful.
This article presents an introduction to structures, how they're coded, and how to capitalize on some of their features. In addition, the concept of nesting structures and arrays - one of the most exciting and powerful uses of data in a ColdFusion application - will be introduced.

Structures and Their Benefits:



Simple variables on a given page are just there, blissfully ignorant of any other variables and happy to store their value. The benefit of structures lies in the logical grouping of the variables. For example, an album on compact disc is an item with several unique values, such as title, artist, and genre. Although each value is unique, they are part of a logical unit: the CD itself.


A structure represents the CD and a number of properties, or keys, within it. By logically grouping the variables in structures, they can be used as members of a cohesive unit. For example, examine the following structure:

CD=StructNew(); CD.Title = "Cookin at the Plugged Nickel"; CD.Artist = "Miles Davis"; CD.Genre = "Jazz";

To view this structure, the following script can be used:


We have a #CD.Genre# CD called #CD.Title# by #CD.Artist#










Resources » Articles » ASP.NET/Web Applications »





Cold Fusion - Array and Structures



Posted Date: 31 May 2010 Resource Type: Articles Category: ASP.NET/Web Applications

Author: Manigandan Member Level: Gold

Rating: Points: 8







Introduction about Cold Fusion,Array and Structures concepts .









COLDFUSION MARKUP LANGUAGE (CFML) is ColdFusions own set of tags that makes up the bulk of the dynamic functionality found on ColdFusion pages. CFML has two different parts that make ColdFusion work: tags and functions. In this chapter we cover a whole bunch of CFML tags and also some basic functions. Chapter 4 shows you how to use some of the more advanced functions and teaches you about variable scopes and different data types.



Tags are used to carry out operations, such as looping over Recordsets, uploading files to a web server by way of a web form, dumping the contents of a variable to the screen for debugging, and grabbing the contents of a remote page on the Web. Functions within ColdFusion are used to manipulate data or perform calculations. For example, ColdFusion has a function called #ArrayAvg()#, which calculates the average of the numeric values within an array. You often must use tags and functions together to build a completely functional site.



HTML and ColdFusion tags can exist together within a document that is requested from a web server. All ColdFusion tags start with

Whenever using ColdFusion tags within a document, you must save it as a.cfmfile for it to be recognized and interpreted by the ColdFusion server.

In text strings, all text is considered literal unless it is within a set of pound/hash (#) signs.



ColdFusion elements (the opening and closing tags, and everything in between) are called blocks. For example, if you were using aelement in your code, it would be called theblock.



To add comments inside ColdFusion tags, you must use CFML comment delimiters:. Notice that these are similar to HTML comments, but have three dashes instead of two. If you use HTML comments inside your CFML, they will not be ignored by the ColdFusion server as expected, and you will either get errors or will dynamically create HTML comments. Also, CFML comments will not send text back to the users browser like HTML comments do.





Array and Structures:



Structures are everywhere in the ColdFusion world. As of ColdFusion 4.5, form, application, session, server, request, and URL variables are stored in structures. Allaire Spectra makes extensive use of structures and associative arrays. But what are they and why should you care?



1.Structures and Their Benefits



2.Structures and Arrays: A Dynamic Duo



3.Extracting Data from Arrays and Structures



4.Nested Arrays



Simply, structures are used to refer to related values as a unit rather than individually. They provide a way to group variables logically. Also, with built-in structure related functions and the ability to nest functions and arrays, variables become much more powerful.



This article presents an introduction to structures, how they're coded, and how to capitalize on some of their features. In addition, the concept of nesting structures and arrays - one of the most exciting and powerful uses of data in a ColdFusion application - will be introduced.





Structures and Their Benefits:



Simple variables on a given page are just there, blissfully ignorant of any other variables and happy to store their value. The benefit of structures lies in the logical grouping of the variables. For example, an album on compact disc is an item with several unique values, such as title, artist, and genre. Although each value is unique, they are part of a logical unit: the CD itself.

A structure represents the CD and a number of properties, or keys, within it. By logically grouping the variables in structures, they can be used as members of a cohesive unit. For example, examine the following structure:



CD=StructNew(); CD.Title = "Cookin at the Plugged Nickel"; CD.Artist = "Miles Davis"; CD.Genre = "Jazz";



To view this structure, the following script can be used:



We have a #CD.Genre# CD called #CD.Title# by #CD.Artist#



This produces:


On the other hand, the StructFind function returns the value associated with the specified key in the specified structure:

We have a #StructFind(CD, "Genre")# CD called #StructFind(CD, "Title")# by #StructFind(CD, "Artist")#

Here is the return:



ColdFusion provides a variety of very handy functions for working with structures, including StructFind used in the CD example above. The StructKeyList function can be used to view (or loop through) a list of the related variables, such as:


A cd consists of

#StructKeyList(CD)#

Structures and Arrays: A Dynamic Duo:



Structures and arrays can be combined to create complex, related data sets that are simple and powerful to use. The CD example provided an interesting way to group three variables logically. However, it only dealt with one CD. For a more complicated example, an online music will be used.


Even though "Cookin at the Plugged Nickel" is a fine album, customers will want to buy other albums as well. If a structure can be thought of as holding multiple properties of an object, then arrays can be thought of as holding multiple instances of an object. When combined, the two produce multiple instances of objects with multiple properties.

No comments:

Post a Comment