views:

217

answers:

1

I have an application.cfc in a subdir of my webroot:

/app/application.cfc

I recently added another application.cfc in a subdir of that and it extends the original application.cfc using the proxy method described here http://corfield.org/blog/index.cfm/do/blog.entry/entry/Extending_Your_Root_Applicationcfc :

/app/mysubdir/application.cfc
/app/applicationproxy.cfc

The extends attribute for the subdir cfc looks like this:

<cfcomponent extends="app.applicationProxy">

This all works fine so far but here's more background: I have been staging my app by putting it in a directory next to /app called /appstaging. This works fine, i.e. there are no conflicts, because I use all relative paths, and my higher-level application.cfc figures out which dir it's in, sets a variable (e.g. application.appdir) and code can use that to construct relative paths if it needs it.

Here's my problem: now that I have that new /app/mysubdir/application.cfc, I need the path for the extends to really be "appstaging.applicationProxy" if this is the staging dir tree. ColdFusion insists though that the value for "extends" be constant. It won't let me figure out where I am and put in the proper dirname like I've been doing everywhere else.

Is there any way to solve this?

+1  A: 

If you're on CF8, use the new this.mappings structure in your application.cfc. It'd look roughly like this. I'll leave it up to you to write the code to figure out whether you're in /app or /appstaging:

if(inAppStaging) this.mappings["/app"] = expandPath("/appstaging");//or whatever... just get a full path to your appstaging directory

This way, when this application.cfc is run under /app, it'll work just as it always has. When it's run in appstaging, it'll tell coldfusion that for this application, "app" points to "appstaging".

marc esher
hmmmm. on second thought, reading it more closely, this probably won't work. drats.
marc esher
I was going to suggest using GetCurrentTemplatePath() and started working up an example when I saw what I bet you see, Marc... the problem is that Application.cfc doesn't have access to the mapping for "/app" until it's done creating it, so it can't extend that. You should be able to do it with a global mapping, though.
Adam Tuttle
I'm on CF7 still (unfortunately). An upgrade is planned but no timeline set yet. I use GetCurrentTemplatePath already to determine if I'm in app or appstaging so I like your idea since it is right in line with how I already work things.
DaveBurns