Tally List : mailing list management, archiving, and analysis
click for archive home
 
Archive of:
CFtipsPlus
Cold Fusion tips email (external)
 
home
24 hour view
quick stats
weekly updates
 
all tallylists
corporate solutions
archive your favorite
help / feedback


Search the Tallylist search by keyword:

About Cold Fusion Tips :
product's home
product's list home
 
  Archived TallyList / CFtipsPlus: 
Subject: 00042 Trimming the fat | Application.cfm
Nathan Stanford (23p/+0r)     Posted: Friday 19 Jan 2001
This post: 147 views, +0 rating

============== ColdFusion TIPS PLUS ColdFusion 01 Volume 01 Issue 03 =============================================================== http://www.cftipsplus.com ============== Issue 00042 ============== I. Comments:

II. ColdFusion Tip: Trimming the fat By Kevin Schmidt, Web Technology Manager Allaire Certified Cold Fusion Developer schmidt@pwb.com

III. JavaScript Tip: Application.cfm Setting global variables Josh Trefethen josh@exciteworks.com

============== I. Comments:

Josh Trefethen has been doing web development for over 5 years, 3 years with Coldfusion. He owns his own consulting business and is currently living in Provo, Utah, where he is president of the the local CFUG. Any questions for Josh can be sent to his email address:

josh@exciteworks.com

=============================================================== If you have any suggestions please email me at cftips@nsnd.com. ===============================================================

=============================================================== II. ColdFusion Tip: Trimming the fat By Kevin Schmidt, Web Technology Manager Allaire Certified Cold Fusion Developer schmidt@pwb.com =============================================================== Trimming the fat...using the trim function in ColdFusion.

The trim function in ColdFusion removes both the leading and trailing spaces in string. So when might this be useful you ask? It is especially useful when processing forms and even more handy if that form information is headed to a database. In the event that a user had accidentaly put in an extra space before their name or after their address this function will remove that space and all will be well.

Lets look at some code examples: In this example we will assume the user entered their first and last names as well as a favorite color. Before we put these into a database we want to make sure to get rid of leading or trailing spaces. The code below will do just that.

<cfset trimmed_first_name = Trim(form.first_name)> <cfset trimmed_last_name = Trim(form.last_name)> <cfset trimmed_favorite_color = Trim(form.favorite_color)>

Now that you have the spaces removed if there were any you can add these to your database without any worries.

Till next week Happy CF'ing.

Coming next week: <cfscript>: what good is it? If you have any questions or suggestions for tips you would like to see feel free to email me at schmidt@pwb.com

Kevin Schmidt, Web Technology Manager Allaire Certified Cold Fusion Developer

============== III. JavaScript Tip: Application.cfm Setting global variables Josh Trefethen josh@exciteworks.com ==============

Application.cfm Setting global variables to allow for increased portablilty

Setting Application variables in your Application.cfm page is a great way to set global variables for use throughout your application. The Application.cfm template is processed each time a script within the directory tree is processed. In other words, the Application.cfm template is automatically included at the top of each file within the same directory tree. Setting variables on this page is a great way to create global variables for use throughout your application. This allows the developer to easily change DSNs, passwords, root directories, and anything else you can dream up.

Please refer to the following code:

<!--- set up the application ---> <CFAPPLICATION NAME="nutracorp" CLIENTMANAGEMENT="YES" SESSIONMANAGEMENT="Yes" SESSIONTIMEOUT="#CreateTimeSpan(0,10,0,0)#" APPLICATIONTIMEOUT="#CreateTimeSpan(1,0,0,0)#">

<cflock scope="APPLICATION" throwontimeout="No" timeout="15" type="EXCLUSIVE">

<cfscript>

//first, check if the variable is defined if (NOT isDefined("Application.DSN")) {

// if not defined, here we set the // global application variables Application.DSN = "myDB"; Application.DB_USER = "admin"; Application.DB_PW = "password1"; Application.root = "/mydirectory/";

} //end if NOT isDefined Application.DSN

</cfscript>

</cflock>

- - - -

(NOTE: I use cfscript here because it is more efficient on the server, but you can set variables the normal way with cfset if you wish)

Now we know how to set these variables in the Application.cfm file. So now lets take things one step further. We can also make our Application.cfm files smarter and our applications more portable by using some variables that are readily available on our servers: CGI variables. By using CFSWITCH with #CGI.SERVER_NAME#, we can determine which server the code is running on and then set the application variables accordingly.

For example:

<cfswitch expression=#CGI.SERVER_NAME#>

<!--- localhost/development server ---> <cfcase value="127.0.0.1"> <!--- set application vars for dev server here ---> </cfcase> <cfcase value="233.122.2.23"> <!---testing server ---> <!--- set application vars for test server here ---> </cfcase> <!--- current production (@intermedia) server ---> <cfcase value="64.78.38.134"> <!--- set application vars for prod server here ---> </cfcase>

<cfdefaultcase> <!--- set application vars for default server here ---> </cfdefaultcase>

</cfswitch>

This way, we can use the same code on numerous machines without changing a thing! I have found this very useful when porting code from a development box to a production server or from my local system to a test machine.

Good luck!

Josh Trefethen josh@exciteworks.com

============== Publisher and Creator: Nathan Stanford, mailto:admin@cftipsplus.com Web Developers: Kevin Schmidt, mailto:schmidt@pwb.com Josh Trefethen, mailto:josh@exciteworks.com Dain Anderson, mailto:danderson@cftipsplus.com ============== Copyright (c) 2000 - 2001 CFTIPSPLUS.COM and NSND.COM Permission is granted to circulate this publication via MANUAL forwarding by email to friends provided that the text is forwarded in its entirety and no fee is charged. ==============

============== To unsubscribe: unsubscribe-cftips@nsnd.com

To subscribe: subscribe-cftips@nsnd.com ==============

____________________________________________________________ T O P I C A -- Learn More. Surf Less. Newsletters, Tips and Discussions on Topics You Choose. http://www.topica.com/partner/tag01


Similar Subject Line Posts (+/- two weeks of this post)
00042 Trimming the fat | Application.cfm  19 Jan 2001 (this post)   (147 v/ +0 r)
 

Send a reply to the CFtipsPlus list!
click to send a reply! NOTE: Many lists will reject your post unless you have already registered with them. Also - don't forget the right account to send from (for those with multiple emails!)

Feedback: If this post was exceptionally helpful, please help by giving this post a positive review.

 

TallyList : copyright Ububik - 2000