Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

coldfusion - Extending application.cfc in a subdirectory

I have the following two files and would like the second to extend the first:

  1. wwwrootsiteapplication.cfc
  2. wwwrootsitedirapplication.cfc

However, when I go to declare the component for the second file, I'm not sure what to put in the extends attribute. My problem is that several dev sites (with a shared SVN repository) are running off the same instance of ColdFusion, so I can't just create a mapping in the CF admin like so:

<cfcomponent extends="site.application">

However, ColdFusion doesn't like:

<cfcomponent extends="..application">

or any dynamic input like:

<cfcomponent extends="#expandpath('..').#application">

Creating a runtime mapping (like here) doesn't seem possible either. Creating it in the base application.cfc is useless because that code hasn't yet executed by the time the inheriting cfc is being declared; and I can't create the mapping before the inheriting component is defined because there isn't yet an application to attach it to.

Is there any way I can reference the parent directory to accomplish my extends?

Edit to clarify: The ApplicationProxy solution doesn't work because of the bolded text above. Right now, as a workaround, we're simply not checking the dirapplication.cfc into SVN so that each developer can keep a version that extends his/her own root application.cfc. Obviously, this is not ideal.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Sean Corfield has a blog entry explaining how to extend a root Application.cfc.

Below is the relevant information copied from that entry.


Here's your root CFC /Application.cfc:

<cfcomponent>

    <cfset this.name = "cf7app" />
    <cfset this.sessionmanagement = true />

</cfcomponent>

Here's your proxy CFC /ApplicationProxy.cfc:

<cfcomponent extends="Application">
</cfcomponent>

It's completely empty and serves merely to create an alias for your root /Application.cfc. Here's your subdirectory CFC /app/Application.cfc:

<cfcomponent extends="ApplicationProxy">

    <cffunction name="onSessionStart">
        <cfoutput><p>app.Application.onSessionStart()</p></cfoutput>
        <cfset session.counter = 0 />
    </cffunction>

    <cffunction name="onRequestStart">
        <cfoutput><p>app.Application.onRequestStart()</p></cfoutput>
        <cfdump label="application" var="#application#"/>
    </cffunction>

</cfcomponent>

The root of each individual site should have its own Master App:

/site1/Application.cfc
/site2/Application.cfc
/site3/Application.cfc

All these applications are separate individual apps with nothing shared between them.

If any of these individual sites need to have sub-applications, then there should be ApplicationProxy.cfc alonside the Master,

e.g.
/site1/ApplicationProxy.cfc
/site2/ApplicationProxy.cfc

Then, for each sub-application you have the one that extends the proxy:

e.g.
/site1/subA/Application.cfc
/site1/subB/Application.cfc
/site2/subA/Application.cfc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...