Copy link to clipboard
Copied
This is complicated to explain, so I hope this makes sense. Here goes...
I have an Application.cfc in the root of my site that sets some variables. I then have an Application.cfc in each subdirectory (Let's call each of these subdirectories a site) that includes the root Applicaiton.cfc. I also have an includes folder that's in the root directory that I use in each site for different pages that I pull in using the cfinclude tag that reference variables set in the root Application.cfc and the site Application.cfc. For some reason, if I hit the page in the includes directory directly everything seems to work okay. I can then go off to the different site pages that use cfinclude to pull in the files in the includes directory, and that works okay too. However, if we come back the next day and don't go directly to the page in the includes directory first and just go to one of the pages that pulls in the include files, we get an error saying that the variables in the root Application.cfc can't be found. I'm not sure where to start to try to debug this one???
This is the entire code from the root Application.cfc minus other variables:
<cfcomponent output="false">
<!--- Application name, should be unique --->
<cfset this.name = "openenrollment">
<!--- Run before the request is processed --->
<cffunction name="onRequestStart" returnType="boolean" output="false">
<cfargument name="thePage" type="string" required="true">
<cfset APPLICATION.memberDisease=True>
<cfreturn true>
</cffunction>
</cfcomponent>
This is the entire code from one of the site Application.cfc files minus other variables:
<cfcomponent output="false" extends="oe.Application">
<!--- Run before the request is processed --->
<cffunction name="onRequestStart" returnType="boolean" output="false">
<cfargument name="thePage" type="string" required="true">
<cfset APPLICATION.group="demo">
<cfreturn true>
</cffunction>
</cfcomponent>
The root of this site is actually a subdirectory named oe that's located in the root of the big site, so the root Application.cfc file lives in the /oe directory. The includes are in the /oe/includes directory, and In the example above the Application.cfc file is in the /oe/demo directory.
I'm new to this cfc stuff, so any help is GREATLY appreciated.
Thanks!
Holli
You're right, that is complicated.
With just one pass through your explanition, my first theory is that the OnRequestStart in your root Application.cfc does not run.
Since you have an OnRequestStart function in the sub Application.cfc file as well, this one will override the OnRequestStart in the base file. They both don't run.
But when you run a file directly in the Includes directory, this file does not use a sub Application.cfc file so it only runs the base Application.cfc file and thus that On
...Copy link to clipboard
Copied
You're right, that is complicated.
With just one pass through your explanition, my first theory is that the OnRequestStart in your root Application.cfc does not run.
Since you have an OnRequestStart function in the sub Application.cfc file as well, this one will override the OnRequestStart in the base file. They both don't run.
But when you run a file directly in the Includes directory, this file does not use a sub Application.cfc file so it only runs the base Application.cfc file and thus that OnRequestStart() function is used.
IF this theory is true, the fix would be to call the parent OnRequestStart() function, from with-in the child OnRequestStart function.
That would probably look something like this.
<cffunction name="onRequestStart" returnType="boolean" output="false">
<cfargument name="thePage" type="string" required="true"><cfset super.OnRewustStart(arguments.thePage)>
<cfset APPLICATION.group="demo">
<cfreturn true>
</cffunction>
Copy link to clipboard
Copied
Awesome! Yes, that fixed it! It sorta makes sense now because when I hit the include files directly, it would pull in the Application.cfc from the root and not have to got through the site Application.cfc file. Thanks!!!
Copy link to clipboard
Copied
@Ian Skinner
<cfset super.OnRewustStart(arguments.thePage)>@Wolli World
Awesome! Yes, that fixed it!
It fixed it, and the page could be rewusted?
Copy link to clipboard
Copied
There might be more trouble ahead with the design. From what I understand, your structure is as follows:
/rootDir
/includes
includedPage1.cfm
includedPage2.cfm
Application.cfc
/site1
Application.cfc [extends rootDir's Application.cfc]
sitePage1.cfm [uses cfinclude tag to pull in includedPage1.cfm and other CFM pages that may reference variables set in the root Application.cfc and in site1's Application.cfc]
/site2
Application.cfc [extends rootDir's Application.cfc]
sitePage2.cfm [uses cfinclude tag to pull in includedPage2.cfm and other CFM pages that may reference variables set in the root Application.cfc and in site2's Application.cfc]
As site1 and site2 represent web sites, each will be distinctly named in its respective Application.cfc. Coldfusion will store that name in application scope. The sessions of a site are bound to the application name. Hence, the sessions in any one of your sites will be distinct from those of another, or from those of the root application..
This begins to look like a river splitting into distributaries. Yet you then introduce pages that bring together variables from the different applications.
In my opinion, this is troublesome design. It appears to be unnecessarily complex. You need to simplify it. Otherwise, it will sooner or later lead to further unpredictable results.