This weekend a reader asked me an interesting question about ColdFusion mappings. Imagine the following two mappings:
- Mapping /org points to /Webserver/Webroot
- Mapping /org/foo points to /projects/foo.com
He was curious to know if this would work right. The second mapping looks to be under org, but really points to a completely different path. I didn't know the answer to this. Every single mapping I've used in the past has always had a simple name, like /org or /foo.
I whipped up a quick test with two mappings named like the examples above. I put the same named CFC in each, but with different methods. I then wrote a quick script:
<cfset test = createObject("component","a.test")>
<cfdump var="#test#">
<cfset test = createObject("component","a.b.test")>
<cfdump var="#test#">
The results showed that there was no problem having mappings with similar names in completely different folders. ColdFusion treats the mapping name as just a simple string. The fact that one was a and one was a/b didn't imply anything special to the server.
The problem - though - would be that if someone put a physical folder named "b" under the folder that my "a" mapping pointed to - there would be a conflict. Which would win? The mapping. I would definitely recommend having mapping names that did not match up like the examples aboe.
Archived Comments
In my early days of ColdFusion I used mappings, which where a terrible headache under shared hosting, now I completely stopped using then. Is there a good reason to use a mapping in the first place? I can't find use for them at all.
Mappings can make life easier. You can cfinclide/cfmodule files a LOT easier with mappings. Any decent ISP will provide you with a mapping. It may be an ugly name, but they will provide you with a mapping.
Mappings are also useful when it comes to hiding important code behind the public facing URL such as your business logic when working with a framework like Mach-II. You can put all your listeners, model, and even the frameworks themselves below the above the webroot and simply create a mapping for them to access them from CF.
what would the practical difference be between a coldfusion mapping and a virtual directory?
A CF mapping only works in CF. A virtual mapping is a web server alias.
Thanks Ray...had physics on the brain, not web dev for the past week so I missed this one. I have to separate accounts on my shared host so I'm gonna test between the two now and see what clashes. Something that has been a bit of a headache for me of late has been the way you have to point at cfcs without mappings when using a html grid.What I found has helped is sticking mapping names and common used folders in an xml file and just loading them into the application on startup.
Regards
Devon