Using only pieces of the Application.cfc?
-
01-07-2021 - |
Question
I don't have any formal training in Coldfusion, so things like this really confuse me because they don't work the way I would assume they would.
My folder structure is this:
MainAppFolder
|
|_ApplicationFolder
|
|_SubAppFolder1
|_Application.cfc
|
|_SubAppFolder2
|_Application.cfc
|
|_Application.cfc
The last Application.cfc contained in the main ApplicationFolder
is the Application.cfc I want to contain my <cflogin>
stuff. That works and it works great. However, a problem arises when I implement the sub Application.cfc in the SubAppFolderx
. Those Application.cfc's only need to contain an onRequestStart
event.
<cffunction name="onRequestStart">
<cfset Application.AppID = 4>
<cfinvoke component="loc"
method="getAppName"
returnvariable="appName" />
<cfset Application.AppName = appName>
</cffunction>
The more I try to fix this problem, the deeper I'm digging myself into a hole. I've attempted to go back and learn more about how to manipulate Application.cfc, but there just isn't much information out there on Coldfusion as far as tutorials go. Documentation for it is great though, but it doesn't help me understand what I need to do in situations like this.
So what do I need to do, to perform what I have in the onRequestStart
in the SubAppFolderx
? I'm sure it's a simple answer, but like I said I'm just digging myself into a hole here.
Solution
While cfinclude is OK, it may not offer the functionality you are after (inheritance) As the Application.cfc is in itself a component, you can overload/override the methods like you would with any other CFC.
I wont go into code, because the legend known as Ben Nadel has already posted a perfect blog for this question:
OTHER TIPS
You could put your login into a cfinclude statement and have the Application.cfc inside SubAppFolder1
- Include the code that is common to all Application.cfc's
- Contain the code that is custom to SubAppFolder1