在 Coldfusion 中自动命名应用程序

Automatically naming applications in coldfusion

我的网站结构如下:

Application.cfc
index.cfm
/Application1/index.cfm
/Application2/index.cfm

如何根据路径自动设置 Application.cfc 中的应用程序名称,使用默认名称?所以如果用户在 index.cfm,我希望名字是 Default Application/Application1/index.cfm 有名字 Application1 等等?

我认为这会奏效,但我不是 100% 确定。您可以尝试扩展application.cfc。 Ben Nadel 在此处 https://www.bennadel.com/blog/2115-extending-the-application-cfc-coldfusion-framework-component-with-a-relative-path-proxy.htm 写了一篇关于此的博客。

下面是一个简化的例子:

Application.cfc(根文件夹)

<cfcomponent output="false">
    <cfset this.name = "Parent" />
    <cfset this.applicationTimeout = createTimeSpan( 0, 0, 10, 0 ) />
    <cffunction name="dummy" access="public" returntype="void" output="true" hint="test">
        <cfreturn />
    </cffunction>

    <cffunction name="onApplicationStart" access="public" returntype="boolean" output="false" hint="I initialize the application.">
        <cfreturn true />
    </cffunction>

    <cffunction name="onRequestStart" access="public" returntype="boolean" output="false" hint="I initialize the request.">
        <cfreturn true />
    </cffunction>

    <cffunction name="onRequest" access="public" returntype="void" output="true" hint="I process the user's request.">
        <cfargument name="script" type="string" required="true" hint="I am the request script." />

        <cfdump var="#this#" label="THIS"/>
        <br />
        <hr />
        <br />
        <cfinclude template="#arguments.script#" />
        <cfreturn />
     </cffunction>

</cfcomponent>

rootApplication.cfc(子文件夹)

<cfinclude template="../Application.cfc" />

Application.cfc(子文件夹)

<cfcomponent extends="RootApplication">
    <cfset this.name = "child" />
</cfcomponent>