Make good use of application variables
Application variables can be used at any time for all pages in the same application. Usually these variables are set in this file, but they can also be set in other single pages. Application variables are very useful for storing data shared by the entire application, such as source name, absolute path or color setting data, etc.
To show the usefulness of application variables, here I plan to explain how to use application variables to store color settings information. Although the share of browsers that support CSS, such as 4.0 and newer versions, are increasing, many users are still continuing to use old browsers. If you are still using the <FONT> tag to set text styles and use the color attribute to set the colors of the table and text, then you should know that when you want to modify the color settings of the website in the future, your nightmare will begin! Using ColdFusion, we can set various colors of the page in another easier and more effective way: that is, store the color settings in the application variables. Once you store the color settings through application variables, you can refer to these colors through the variable names, instead of directly writing the color names (or 16-carry color codes) into the program. Further, you only need to modify the values of these application variables, and the colors in all relevant pages will change together.
In your file, you can set an application variable so that its value contains a blank structure (the structure is a key-value pairing or a two-dimensional array):
<CFSCRIPT>
=structNew();
</CFSCRIPT>
This way you have an application variable called , whose value is a blank structure. Next you can store the color names you need to use in this blank structure. Here is an example:
<CFSCRIPT>
=structNew();
='FFFFFF';
='708090';
='C0F171';
='131E63';
='C01531';
='FFFFE6';
</CFSCRIPT>
Now you no longer need to write the color name directly into your page, just refer to the variables inside. For example, in the <BODY> tag you can use the following writing method:
<CFOUTPUT>
<BODY
BGCOLOR="##"
TEXT="##"
LINK="##">
</CFOUTPUT>
You can apply this technique to tables, frames, or anywhere else where color attributes are used. This way, you can easily adjust the color settings of the website at any time, because all colors are stored in the same place and are very easy to modify.
Remember to lock it in time
When reading or setting variables in scope such as application, user status, or server, it is very important to use the CFLOCK volume label to lock variables within the appropriate variable range. The CFLOCK volume label can ensure the integrity and consistency of shared information, and this work is particularly important on high-traffic servers. If you need more information on this, please read your instructions for use, or refer to this article on the ColdFusion Developer's Journal website.
Previous page12345Read the full text