RE: if/switch cf:set/param
Jacob, Excellent point. I love to use Cfparam for type=numeric and put a try/catch around it. I have not used it for the new CF-7 param types yet, but it's a great tag. ... Ben Nadel Web Developer Nylon Technology 350 7th Avenue Floor 10 New York, NY 10001 212.691.1134 212.691.3477 fax www.nylontechnology.com You know, like nunchuck skills, bowhunting skills, computer hacking skills... Girls only want boyfriends who have great skills. - Napoleon Dynamite -Original Message- From: Munson, Jacob [mailto:[EMAIL PROTECTED] Sent: Thursday, June 01, 2006 5:37 PM To: CF-Talk Subject: RE: if/switch cf:set/param One thing I haven't seen anybody else mention is that cfparam can be used for data validation, using the type attribute. For example, if you are expecting an email address from a form, you can do a cfparam with type=email and CF will throw an error if the data doesn't match (the email type is new to CF 7). -Original Message- From: Paul Ihrig [mailto:[EMAIL PROTECTED] Sent: Thursday, June 01, 2006 3:55 PM ok. just looking at a bunch of code. most pages use a combo of if switch what are the reasons to use one over the other. also what is the difference between cfset cfparam. i know cfset sets the variable you want to be but dosnt cfparam also do this? This transmission may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. A1. ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:242022 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: if/switch cf:set/param
If you're doing a large comparison set, my understanding is that switch is better for performance. As for cfset vs cfparam, cfset sets the variable and overwrites and previous value that the variable held. Cfparam sets the variable if it doesn't already exist. Basically, cfparam ensures that the variable has a value when you try to use the variable, however, if the variable is set elsewhere prior to the cfparam, the cfparam is ignored. John Burns Certified Advanced ColdFusion MX Developer Wyle Laboratories, Inc. | Web Developer -Original Message- From: Paul Ihrig [mailto:[EMAIL PROTECTED] Sent: Thursday, June 01, 2006 3:55 PM To: CF-Talk Subject: cf:if/switch cf:set/param ok. just looking at a bunch of code. most pages use a combo of if switch what are the reasons to use one over the other. also what is the difference between cfset cfparam. i know cfset sets the variable you want to be but dosnt cfparam also do this? also what should i know about variable pools? thanks -paul ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:241976 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: if/switch cf:set/param
Paul, CFSwitch I believe is faster (slightly) , and I think easier to read. Also, the default case does not need to be the last case (as opposed to an ELSE statement). However, the tradeoff is that the case values have to be contstants. For IF statements, the benefits are the possibility of dynamic comparisons (ie. URL.x EQ URL.y ). Mostly though, it's a matter of personal preference I think. Cfset sets a value into a variable. Cfparam checks to see if a variable already exists. If it does not exist and a default was provided, it sets that value into the variable. If no default exists, it throws an error. I think there are a lot of different opinions on why/when it is appropriate to use CFParam vs setting a variable. I like to CFParam all my FORM variables and custom tag ATTRIBUTES (as an example). I like to know that a value exists, even if it isn't correct, because then I can validate afterwards. However, in Custom tags, I ususally don't have default values for all my attribute params so that CF will throw an error if the user does not provide the attribute. If by variable pools, you mean scopes (ex. APPLICATION, SESSION, REQUEST), they are fantastic! I scope (define within the context of a variable poo, ex. FORM.first_name) anything that is either submitted to a page or is available in more than one template. So for example, if I use an index variable that is for only one template, I might use intChild, but if I use a variable that is set in one template and used in another, I might use something like REQUEST.ChildIndex... It becomes a naming convention that I love because the structure of the variable helps explain what it is and where it was set/available. There is lots to know about the different scopes and how widely accessible they are. Check out the main ones in the live docs. ... Ben Nadel www.bennadel.com -Original Message- From: Paul Ihrig [mailto:[EMAIL PROTECTED] Sent: Thursday, June 01, 2006 3:55 PM To: CF-Talk Subject: cf:if/switch cf:set/param ok. just looking at a bunch of code. most pages use a combo of if switch what are the reasons to use one over the other. also what is the difference between cfset cfparam. i know cfset sets the variable you want to be but dosnt cfparam also do this? also what should i know about variable pools? thanks -paul ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:241977 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: if/switch cf:set/param
A good example of the usage of cfparam involves when you're using input type=checkbox on a form. If the user doesn't check the checkbox, the form field is not posted at all, so an attempt to evaluate it using form.checkboxfield (example) results in field undefined in form error. Using cfparam name=form.checkboxfield default=0 on your form processing page alleviates that problem nicely. If the checkbox is checked (assuming the checked value is 1), form.checkboxfield evaluates to 1. If it's not checked, it evaluates to 0 because of the cfparam tag. Of course there are a million other uses for it, but I think the first time I ever used it was in that context. -- Josh - Original Message - From: Ben Nadel [EMAIL PROTECTED] To: CF-Talk cf-talk@houseoffusion.com Sent: Thursday, June 01, 2006 2:01 PM Subject: RE: if/switch cf:set/param Paul, CFSwitch I believe is faster (slightly) , and I think easier to read. Also, the default case does not need to be the last case (as opposed to an ELSE statement). However, the tradeoff is that the case values have to be contstants. For IF statements, the benefits are the possibility of dynamic comparisons (ie. URL.x EQ URL.y ). Mostly though, it's a matter of personal preference I think. Cfset sets a value into a variable. Cfparam checks to see if a variable already exists. If it does not exist and a default was provided, it sets that value into the variable. If no default exists, it throws an error. I think there are a lot of different opinions on why/when it is appropriate to use CFParam vs setting a variable. I like to CFParam all my FORM variables and custom tag ATTRIBUTES (as an example). I like to know that a value exists, even if it isn't correct, because then I can validate afterwards. However, in Custom tags, I ususally don't have default values for all my attribute params so that CF will throw an error if the user does not provide the attribute. If by variable pools, you mean scopes (ex. APPLICATION, SESSION, REQUEST), they are fantastic! I scope (define within the context of a variable poo, ex. FORM.first_name) anything that is either submitted to a page or is available in more than one template. So for example, if I use an index variable that is for only one template, I might use intChild, but if I use a variable that is set in one template and used in another, I might use something like REQUEST.ChildIndex... It becomes a naming convention that I love because the structure of the variable helps explain what it is and where it was set/available. There is lots to know about the different scopes and how widely accessible they are. Check out the main ones in the live docs. ... Ben Nadel www.bennadel.com -Original Message- From: Paul Ihrig [mailto:[EMAIL PROTECTED] Sent: Thursday, June 01, 2006 3:55 PM To: CF-Talk Subject: cf:if/switch cf:set/param ok. just looking at a bunch of code. most pages use a combo of if switch what are the reasons to use one over the other. also what is the difference between cfset cfparam. i know cfset sets the variable you want to be but dosnt cfparam also do this? also what should i know about variable pools? thanks -paul ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:241983 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: if/switch cf:set/param
One thing I haven't seen anybody else mention is that cfparam can be used for data validation, using the type attribute. For example, if you are expecting an email address from a form, you can do a cfparam with type=email and CF will throw an error if the data doesn't match (the email type is new to CF 7). -Original Message- From: Paul Ihrig [mailto:[EMAIL PROTECTED] Sent: Thursday, June 01, 2006 3:55 PM ok. just looking at a bunch of code. most pages use a combo of if switch what are the reasons to use one over the other. also what is the difference between cfset cfparam. i know cfset sets the variable you want to be but dosnt cfparam also do this? This transmission may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. A1. ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:241985 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54