Skip to main content
Inspiring
March 8, 2013
Question

Can't get this.mappings to work

  • March 8, 2013
  • 2 replies
  • 3756 views

Okay, I'm stumped enough to break a laptop.  I've been reading every post I can find today on how to setup per-Application mappings, and it just doesn't work.  Here's my situation:

I have an existing site running on Linux under CF 9.0.1, and I had Mappings configured in CF Admin for 2 directories that I use in cfinclude tags throughout my CFMs and CFCs (so that those directories can remain above the webroot and not be exposed by Apache).  All that worked fine forever.

Now I need to set up a second site with a separate set of directories, but I'm starting with a copy of the existing site's folders and then modifying the paths as needed.  For example, my first site is in /web/website, and my mappings are for "/cf-include" and "/cfc" mapped to "/web/website/cfc" and "/web/website/cf-include" in the Admin.  My webroot is "/web/website/htdocs", which is configured as my DocumentRoot in Apache.  For my second site, I created a new directory "/web/stwebsite" containing copies of the same directories, and created a VirtualHost in Apache with a DocumentRoot of "/web/stwebsite/htdocs".  I then added the following two mapping lines to my new Application.cfc (in that new directory), outside any of the functions :

<cfcomponent displayname="Application" output="True" hint="Handle the application.">

<cfset this.name="stapp">

<cfset this.Sessionmanagement=False>

<cfset this.ApplicationTimeout=CreateTimeSpan(1,0,0,0) />

<cfset this.setClientCookies=False>

<cfset this.mappings["/cf-include"]="/web/stwebsite/cf-include">

<cfset this.mappings["/cfc"]="/web/stwebsite/cfc">

...

I also made sure I had the Enable Per-App Settings checked in my CF Admin (it already was).  However, when I try to use those mappings, I get the one from the Admin and not the Application.cfc:

<cfinclude template="/cf-include/sttest.cfm">

I verified this by changing the content of that file in the two different directories and seeing which version showed up.

So my question is, what's preventing the this.mappings settings from being used?  Am I wrong in understanding that I should be able to set those in the Application.cfc for the new site (which IS being used for that site, I verified that by changing what happens in the OnApplicationStart method) and have them supercede the Admin settings?  I also tried deleting the Mappings in the Admin, but that left all the cfincludes failing (saying the mapping didn't exist).  What am I missing?

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
March 9, 2013

<cfset this.mappings["/cf-include"]="/web/stwebsite/cf-include">

<cfset this.mappings["/cfc"]="/web/stwebsite/cfc">

Potential problem: Including a hyphen in a directory name may cause problems when your site interacts with systems (like Java) where hyphens are disallowed in names. Replace cf-include with, say, cf_include.

Problem: The right-hand side should be an absolute path instead. Hence, something like

<cfset this.mappings["/cf_include"]=expandPath("/web/stwebsite/cf_include")>

<cfset this.mappings["/cfc"]=expandPath("/web/stwebsite/cfc")>

Inspiring
March 9, 2013

I'll try renaming that directory, but I also have an issue with the other directories that don't have hyphens in their names. Do you think having one element like that would render the whole mappings structure useless?

As for the absolute paths, I already replied that those are my absolute paths because I'm on Linux.

Mike Simone

BKBK
Community Expert
Community Expert
March 9, 2013

jarviswabi wrote:

I'll try renaming that directory, but I also have an issue with the other directories that don't have hyphens in their names.  Do you think having one element like that would render the whole mappings structure useless?

No, I don't think so. In fact, given your explanation, I expect your original code to work. Yes, even with the hyphen!

As for the absolute paths, I already replied that those are my absolute paths because I'm on Linux.

OK. Then ignore expandPath(). After all, it will just return the same absolute path.

Let's do some tests. Does this work:

<cfinclude template="/web/stwebsite/cf_include/sttest.cfm">

Is your application file named Application.cfc, starting with capital A?

Inspiring
March 9, 2013

Mapping use absolute path. I did it like this:-

<cfset THIS.rootPath = GetDirectoryFromPath(GetCurrentTemplatePath()); /> // This gives me current directory of

                                                                                                                 // application.cfc i.e absolute path

                                                                                                                 // of my root

<cfset THIS.mappings["/model"] = "#THIS.rootPath#/my_folder/Model"; /> // Then i append rest path to it

Inspiring
March 9, 2013

I did use absolute paths. This is Linux, so my absolute paths are "/web/stwebsite/cfc", etc.