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 549 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 549 days ago
Add Comment Reply to: this comment OR this thread
 
Joe said:
 
That's really, really great news for shared hosting!!
 
posted 549 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 110 days ago
Add Comment Reply to: this comment OR this thread
 

Search

About Me
I am a 32-year old Web Developer specializing in ColdFusion. I live and work in downtown Washington, DC with my wife and daughter. 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.