Over the last year, I've learned alot about ColdFusion, AJAX, and DBA stuff. I have to say, however, that the coolest thing I've learned is that in ColdFusion 8 you can set per application mappings in the Application.cfc itself. Why is this so cool? Well, I tend to create a lot of folders in my applications in order to keep related assets in one place together. Of course, creating mappings to these folders makes life a lot easier in that you don't have to worry about making sure you are referencing these folders correctly in different contexts–with mappings ColdFusion can take of that for you.

However, the problem I often run into is that I have to create some funky mapping names in CF Administrator in order to keep them all unique. In my local host environment, for example, the number of mappings is huge and it becomes a hassel to remember to re-set these mappings up when I push final code to a production environment (not to mention that some hosting providers make doing this a lot harder than you could imagine…).

But with CF8, this is no longer a problem. Now you can create dynamic mappings in APplication.cfc, and not have to bother with setting up an actual mapping in CF Administrator.

So how do you do this? Very simply! Here's a sample from Application.cfc from one of my apps:

<cfset this.name = "myApp">
<cfset this_dir = getDirectoryFromPath(getCurrentTemplatePath()) />
<cfset this.mappings["/includes"] = this_dir & "\includes" />
<cfset this.mappings["/proc"] = this_dir & "\admin_proc" />
<cfset this.mappings["/admin"] = this_dir & "\admin_includes" />

In the second line, I'm simply getting the root context of the application, where Application.cfc lives. From there, I populate Application.cfc's "mappings" array with whatever specific mappings I need, appending the mapping location to the root context of the application.

Now that these are setup, I can use the mapping just as I would a mapping set up in CF Administrator–for example:

<cfinclude template="/includes/top.cfm" />

So yeah, I think this is amazing and I've already reaped the benefits of it in several different applications. Obviously, there are a lot of other posts out there about this, but I hope this is helpful to someone.