For everyone who *wishes* they could go to CFUnited
Adam
Here's something to stick in your sidebar. I added it to mine yesterday.

Posted in CFUnited | ColdFusion |
Adam
Here's something to stick in your sidebar. I added it to mine yesterday.

Posted in CFUnited | ColdFusion |
Adam
[viewcode] src="cfx_imagecr3_support1.cfm.txt" showsyntax=no geshi=cfm[/viewcode]
This would have made it very easy to wrap any block of code in a try/catch that will email me on error. As it turns out, this isn't possible without some clever use of CFFile and Regex to read the contents of the calling template and locate the block of code between the start and end tag of the custom tag. But I'm sure you're already thinking about how inefficient that would be, especially in my case where there are 20, 30, maybe more instances. And I agree with you. Then, it hit me like a ton of bricks: Take one step back — just the one tag causing my grief, not a general code block — and write a wrapper for that one tag. And to make things even simpler: Use AttributeCollection! I can pass easily everything sent to my wrapper on to the CFX as an AttributeCollection, without knowing what it is. So I slammed together a quick wrapper custom tag (File name: "/customtags/wrappers/cfx_imagecr3.cfm") as this: [viewcode] src="cfx_imagecr3.cfm.txt" showsyntax=no geshi=cfm[/viewcode] Notice that after I save the contents of my special attributes (try_mailto and try_subject), I delete them from the attributes struct. Different tags and CFXes will react differently to unexpected attributes, so it's best not to include them. After simply importing my new tag wrapper:[viewcode] src="cfx_imagecr3_support.cfm.txt" showsyntax=no lines=1 geshi=cfm[/viewcode]
This tag:[viewcode] src="cfx_imagecr3_support.cfm.txt" showsyntax=no lines=2 geshi=cfm[/viewcode]
Becomes this tag:[viewcode] src="cfx_imagecr3_support.cfm.txt" showsyntax=no lines=3 geshi=cfm[/viewcode]
I can customize the to address and subject of the email per-usage, if I like, and I get an email any time one of them fails.Posted in ColdFusion |
Adam
Posted in ColdFusion | Frameworks |
Adam
Adam
Update: It's been brought to my attention that the CGI variables will differ depending on whether you're using Apache, IIS, or another server software. It should still be possible and the concepts will be the same, you just may need to adjust the code to fit your environment. My code was developed on CF8 / IIS, and my demo runs on CF5 / IIS.To accomplish the same thing with CF code, we need 2 pieces of information from the ever-helpful CGI scope: script_name and path_info. Script_name is everything after the TLD (.com/etc) until the end of the actual script name. Path_info contains everything after the TLD, including the query string. The reason we can't just use query_string is that once you convert your URLs to be /in/a/simulated/folder/format, they are not populated into query_string, only into path_info. So for example, if my URL was
http://somesite.com/Vader/isms.cfm?ism=iamyourfather, then CGI.SCRIPT_NAME would have the value /Vader/isms.cfm and CGI.PATH_INFO would have the value /Vader/isms.cfm?ism=iamyourfather.
For comparison, when using /simulated/folder/format, the URL would be http://somesite.com/Vader/isms.cfm/ism/iamyourfather. In this case, CGI.SCRIPT_NAME is still the same: /Vader/isms.cfm, and CGI.PATH_INFO is slightly different, but probably what you expect: /Vader/isms.cfm/ism/iamyourfather
<cfset newQ = right(cgi.path_info, len(cgi.path_info)-len(cgi.script_name)-1) /> <cfif newQ contains "/"> <cfloop from="1" to="#ListLen(newQ, '/')#" step="2" index="e"> <cfset url['#listGetAt(newQ, e, "/")#'] = listGetAt(newQ, e+1, "/") /> </cfloop> </cfif>
You can see a demo page here, where I've added the above code to my Application.cfm, and the page I'm linking to will dump the URL scope. This is a fairly simple system of name/value pairs embedded as what I call "simulated folders." It would be fairly simple to setup a more complex system using Regex and your own rules, and this should provide a good base for that. Also note that this system will break if you use an odd number of slashes — for example if you add a trailing slash to the end, or if you use the format 1/2/3, without a value for the variable name you're creating in position 3.<cfset newQ = cgi.path_info/> <cfif not len(cgi.path_info) eq len(cgi.script_name)> <cfset newQ = right(newQ, len(newQ)-len(cgi.script_name)-1) /> <cfif newQ contains "/"> <cfloop from="1" to="#(listLen(newQ, '/') – (listLen(newQ, '/') mod 2))#" step="2" index="q"> <cfset url['#listGetAt(newQ, q, "/")#'] = listGetAt(newQ, q+1, "/")/> </cfloop> </cfif> </cfif>
Posted in ColdFusion |