我正在使用Application.cfm切换到Application.cfc,我正在使用Ben Nadel的方法来使用应用程序代理将我的应用程序扩展到子文件夹中。 (link to article)通过根代理扩展Application.cfc时如何防止<cfincludes>中断?
我遇到的问题是,当我在一个子文件加载页面的所有cfinclude标签被称为根的Application.cfc文件弹出一个“找不到包含的模板...“错误消息。 (该包括故意的成分,所以我可以设置应用程序特定变量的顶部)
这里有几个要求:
- 应用程序有没有访问到ColdFusion管理员来运行。
- 应用程序可能或可能不驻留在另一个站点(即www.example.com/或本地主机/ mysite的/)
这里的子文件夹的文件结构:
- /application.cfc
- /include_me.cfm
- /index.cfm
- /sub/application.cfc
- /sub/application_rootProxy.cfc
- /sub/index.cfm
根Application.cfm:
<cfcomponent
output="false"
hint="I define the application settings and event handlers.">
<!--- Define the application settings. --->
<cfset this.name = "TestApplication" />
<cfset this.applicationTimeout = createTimeSpan(0, 0, 10, 0) />
<!---
Store the path of the current template. We want to see if
this shows up as the root template or the sub template.
--->
<cfset this.ROOT_currentTemplatePath = getCurrentTemplatePath() />
<!--- Set a variable to indicate that the included file hasn't been run yet --->
<cfset this.includedFile = "no" />
<!--- include the file --->
<cfinclude template="include_me.cfm" />
<cffunction
name="onApplicationStart"
access="public"
returntype="boolean"
output="false"
hint="I initialize the application.">
<!--- Set some app variables for testing. --->
<cfset application.ROOT_onApplicationStart = true />
<!--- Return true so the page can process. --->
<cfreturn true />
</cffunction>
<cffunction
name="onRequestStart"
access="public"
returntype="boolean"
output="false"
hint="I initialize the request.">
<!--- Set some request variables for testing. --->
<cfset request.ROOT_onRequestStart = true />
<!--- Return true so the page can process. --->
<cfreturn true />
</cffunction>
<cffunction
name="onRequest"
access="public"
returntype="void"
output="true"
hint="I process the user's request.">
<!--- Define arguments. --->
<cfargument name="script"type="string" required="true"hint="I am the request script." />
<!--- Output the current THIS collection. --->
<cfdump var="#this#" label="THIS" />
<!--- Include (execute) requested script. --->
<cfinclude template="#arguments.script#" />
<!--- Return out. --->
<cfreturn />
</cffunction>
</cfcomponent>
根Include_me.cfm:
<!--- update the value so we know the file was indeed included --->
<cfset this.includedFile = "yes" />
子文件夹的Application.cfc
<!--- extends the application so we can make changes when needed --->
<cfcomponent extends="application_rootProxy">
\t
\t <cfset this.SUB_currentTemplatePath = getCurrentTemplatePath() />
</cfcomponent>
子文件夹的根代理:
<cfinclude template="../application.cfc">
什么是正确的方式,让cfinclude标签基础的Application.cfc当你通过代理服务器的根访问应用程序?
我最初的直觉是看我是否可以动态计算应用程序根目录,幸运的是getCurrentTemplatePath()能够区分子application.cfc和根application.cfc。但是,当您尝试通过本地文件系统链接访问它们(例如d:\ mysite \ include_me.cfm)时,cfincludes不起作用。看起来我需要根据执行的application.cfc的子目录找出包含文件的动态相对位置。任何和所有的帮助表示赞赏!
好像我们刚刚在另一个线程上回答了这个问题。有人记得吗? – 2014-12-03 19:15:44
没关系 - 这是这个线程:http://stackoverflow.com/questions/26913828/multi-application-coldfusion-7-server-and-cfc-paths/26915356 - 我不认为它适用戴夫。 – 2014-12-03 19:17:46
Dave,在您的应用程序设置中,您是否可以设置映射到您想要的位置?然后将它用作包含文件的别名? – 2014-12-03 19:19:41