Staging my Coldfusion app when using CFC inheritan

2019-08-17 09:50发布

问题:

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:

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".