在coldfusion中自动命名应用程序

时间:2018-04-17 16:08:22

标签: coldfusion

我的网站结构如下:

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

如何根据路径自动在Application.cfc中设置应用程序名称,并使用默认名称?因此,如果用户位于index.cfm,我希望名称为Default Application/Application1/index.cfm的名称为Application1,依此类推?

1 个答案:

答案 0 :(得分:2)

我认为这会奏效,但我不是百分百肯定。您可以尝试扩展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(根文件夹)

body,
html {
  margin: 0;
  padding: 0;
}

.crop {
  width: 100%;
  height: 50%;
  overflow: hidden;
  background-color: red;
  text-align: center;
}

#cropped-img {
  position: relative;
  height: 100%;
  width: 100%;
  max-width: 100%;
  display: block;
  margin: 0 auto;
}

rootApplication.cfc(子文件夹)

<div class="crop">
  <img id="cropped-img" src="http://img1.jurko.net/wall/paper/donald_duck_4.jpg" />
</div>

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>