0

ColdFusion 8: Per App Dynamic Mappings and Custom Tag Paths Create Dropable Applications

ColdFusion 8

One small but really cool feature of ColdFusion 8 is the ability to define mappings and custom tag paths within an Application.cfc file. It is now possible to create dynamic mappings and with that completely dropable applications. I've always liked the concept of CF mappings but not the hassle of configuring every server for my mappings. CF8 removes the later concern and now it can fully use the power of CF mappings.

Lets take a look inside an Application.cfc:

Thats it! Drop this cfc on any folder on any server and the mapping "mymap" will work. Sure makes referencing cfc's a whole lot easier.

Same thing for custom tags except this time I designated a tags folder for my custom tags. You can specify multiple custom tag paths by using a list of paths that get checked in order. Likewise you can add as many mappings as you like.

How does getDirectoryFromPath and getCurrentTemplatePath functions work? Neither are new to 8, the getCurrentTemplatePath function will always return the full system path to the current file (not the requested) whether its a cfm or cfc. GetDirectoryFromPath simply strips the file from the path and gives us exactly what we want in this case.

Why not place these settings in the onApplicationStart function?

The way I look at it the "this" scope is how you define the application to the ColdFusion engine while application variables and anything that happens in the onApplicationStart function are something programmers use.

tags:
ColdFusion 8
Brian Swartzfager said:
 
Hi, Sam,

Possible typo in your code block: you name your mapping "mymap" instead of "myApp" as stated in your post.
 
posted 763 days ago
Add Comment Reply to: this comment OR this thread
 
 
Ah, yeah. Thanks for spotting that. I copied and pasted everywhere when coding for this example except for when I was writing this blog entry.

I am going to fix the posting for clarities sake.
 
posted 763 days ago
Add Comment Reply to: this comment OR this thread
 
Joe said:
 
That's really, really great news for shared hosting!!
 
posted 763 days ago
Add Comment Reply to: this comment OR this thread
 
Cliff Freeman said:
 
Hi Sam
I hoped that your this.mappings would be the solution but not yet! I have added your code to my Application.cfc but using cfinclude="/mymap/filename.cfm" simply gives me a 'can't find file' error or if loading a file that has an image in it the image doesn't load even when the image file is cfinclude="/mymap/imagefilename.jpg. Any suggestions?
Thanks
Cliff
 
posted 324 days ago
Add Comment Reply to: this comment OR this thread
 
Chris Luksha said:
 
How do you then use the mappings to call your cfc? I can't for example call this.org.ews.mycfc. If I used the mappings and my folder structure looked like this:
root/org/ews/mycfc.cfc
root/admin/index.cfm
how does admin/index.cfm access root.org.ews.mycfc?

I have been trying to figure this out and yours is the first post to confirm for me WHY I want to the mappings - but I have yet to see HOW to use the mappings

thanks,
Chris
 
posted 157 days ago
View Replies (2) || Add Comment Reply to: this comment OR this thread
 
.: HIDE REPLIES :.
samfarmer said:
 
@Chris: so in root/Application.cfc you should have:
this.mappings["/mymap"] = getDirectoryFromPath(getCurrentTemplatePath())

Then in admin/index.cfm:
myObj = createObject("component","mymapp.org.ews.mycfc")

To test if it worked:
cfdump var="#myObj#"

(All brackets removed)
 
posted 157 days ago
Add Comment Reply to: this comment OR this thread
 
Chris Luksha said:
 
Now it is just amazing how the simple things in life are in fact the best. Thank you so much for helping me understand that Sam. I was digging for a while as to why I saw that mapping in a few Application.cfc examples around the net.

Thanks again - so much You made my night.
Chris
 
posted 157 days ago
Add Comment Reply to: this comment OR this thread
 
samfarmer said:
 
@Chris: so in root/Application.cfc you should have:


Then in admin/index.cfm:


To test if it worked:
 
posted 157 days ago
Add Comment Reply to: this comment OR this thread
 
WOW gold said:
 
 
posted 72 days ago
Add Comment Reply to: this comment OR this thread
 

Search

About Me
I am a 33-year old Web Developer specializing in ColdFusion. I live and work in downtown Washington, DC with my wife and two daughters. I work for Interfolio where we help people collect, deliver and showcase their life's work. Read more About Me

2007 CFeMmy Best Newcommer winner
As voted on by fellow CF Bloggers.
I will be attending these conferences in 2009. If you are going let me know!