Making Your Application Portable The Application.cfm file can be a very powerful one. Many developers use this file to define as many Application variables as possible. Putting as many variable values and application settings as possible into the Application.cfm file makes your application much more portable. For example, imagine this very common scenario. You are the company's ColdFusion guru, and you have developed a super groovy intranet web application for company employees to use. The site has grown to include hundreds of pages and dozens of queries. The IT department is upgrading some servers, and you are forced to move the application onto another server. In the course of this reshuffle, you will be forced to use a different data source name. Now you have to trawl through hundreds of pages to find out which ones use queries. You then have to change the data source name in each and every one of the dozens of queries, a painful exercise. Now imagine that when you began this application, you knew about the virtues of the Application.cfm file, and you included the following line of code there: <CFSET MyAppDSN="Staff"> From then on, whenever you wrote each query, you used the variable in place of the usual data source name, as follows: <CFQUERY NAME="qStaffList" DATASOURCE="#MyAppDSN#"> SELECT * FROM Employees </CFQUERY> Because the Application.cfm file gets included at the top of every request, each page should know the value of the #MyAppDSN# variable. Now, when you need to change the data source for your hundreds of pages and dozens of queries, you simply open your Application.cfm file and change the value of the #MyAppDSN# variable in that one line of codeand you're done. By packing as many settings into the Application.cfm file as possible, it also makes it easy to send your application to a branch office. They could put the files on their server, simply open the Application.cfm file, change the settings to match their own environment, andpresto!be up and running. All your settings are in one place, are easy to keep track of, and are easy to change. Beautiful. |