When extending Application.cfc through a root proxy How to prevent <cfincludes> from breaking?
I am switching to using the Application.cfm application in Application.cfc, and I am using the Ben Nadel method to expand my application into a subfolder using the application proxy. ( link to the article )
The problem is that when I load the page into a subfolder, all the cfinclude tags that call in the root Application.cfc file cause a "Could not find the included template ..." error message. (Include intentionally at the top of the component so that I can set specific application variables)
Here are a few requirements:
- The application must be running without access to the ColdFusion administrator.
- The application may or may not be located in a subfolder of another site (for example, www.example.com/or localhost / mysite /)
Here is the file structure:
- /application.cfc
- /include_me.cfm
- /index.cfm
- /sub/application.cfc
- /sub/application_rootProxy.cfc
- /sub/index.cfm
Root 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 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>Root Include_me.cfm:
<!--- update the value so we know the file was indeed included --->
<cfset this.includedFile = "yes" />Subfolder Application.cfc
<!--- extends the application so we can make changes when needed --->
<cfcomponent extends="application_rootProxy">
<cfset this.SUB_currentTemplatePath = getCurrentTemplatePath() />
</cfcomponent>Root proxy file subfolder:
What is the correct way to enable cfinclude tags in a .cfc base application when you access the application through a root proxy?
, , , , getCurrentTemplatePath() sub application.cfc root application.cfc. cfincludes , (, d:\mysite\include_me.cfm). , - .cfc. !
-... , , - .
, cfinclude OnRequest() , . , cfincludes , .
, cfincludes :
, :
<cfcomponent>
<!--- call the method which includes the file --->
<cfset includeFile() />
<!--- new method for including the file --->
<cffunction name="includeFile">
<cfinclude="include_me.cfm">
</cffunction>
...
</cfcomponent>, , application.cfc, .
, , , Application.cfc
, , , .
: https://gist.github.com/daccfml/3ed091c62d688595d66e
/Application.cfc
component {
writeOutput("#getCurrentTemplatePath()# called<br>");
include "inc.cfm";
}
/inc.cfm
<cfoutput>#getCurrentTemplatePath()# called<br></cfoutput>
/ApplicationProxy.cfc
component extends="Application" {
writeOutput("#getCurrentTemplatePath()# called<br>");
}
/sub/Application.cfc
component extends="ApplicationProxy" {
writeOutput("#getCurrentTemplatePath()# called<br>");
}
/sub/test.cfm
<cfoutput>#getCurrentTemplatePath()# called<br></cfoutput>
:
C:\wwwroot\Application.cfc
C:\wwwroot\inc.cfm
C:\wwwroot\ApplicationProxy.cfc
C:\wwwroot\sub\Application.cfc
C:\wwwroot\sub\test.cfm
, .
, , , , . , , .