Extending Application Component
Tags: Coldfusion
Awhile ago as posted on the cfaussie mailing list, a user was having problems with paths. I am not sure what the exact problem is the user was having, nor do I know how he was extending the Application.cfc.
But here is an example that works under Coldfusion 8, so I will assume it should also work under Coldfusion MX7. First the ApplicationProxy.cfc
</cfcomponent>
Now the Root Application.cfc
<cfset this.mappings['/Reactor'] = getDirectoryFromPath(getCurrentTemplatePath()) & '../Reactor' />
</cfcomponent>
Now the Application.cfc to be extended.
<!--- Request Start --->
<cffunction name="onRequestStart" returntype="boolean" output="true">
<cfargument name="thePage" type="string" required="true">
<cfoutput>This is the sub application</cfoutput>
<cfdump var="#this#">
<cfreturn true />
</cffunction>
</cfcomponent>
And the output is as expected, I thought I would throw this up here for two reasons. One for proof of concept that it does work, and most importantly to see if Coldfusion 8 would suffer from this bug that was being described. The reason that this is important, is that the this.mappings is always reset on the fly each and every time the application.cfc is loaded.
-
Ok, very quickly made a change and found the problem that was being seen by this user.
To overcome the problem, I did this.
In the root Application.cfc, in no functions I did this.newPath = getDirectoryFromPath(getCurrentTemplatePath()) & '../Reactor' and added the following code to the application.cfc that was extending the root application
<!--- Application Start --->
<cffunction name="onApplicationStart" returntype="boolean" output="false">
<cfset Application.newPath = this.newPath />
<cfreturn true />
</cffunction>
Seems like a small hack, but it works.# Posted By Andrew Scott | 6/9/07 12:18 AM -
Hmm... I should have explained that a little better. The problem, is that when creating a path to be used in the application scope. Can inherit the parents code, but doesn't inherit the parents path. What that means is that the ExpandPath can be the wrong directory.
# Posted By Andrew Scott | 6/9/07 4:01 AM



TweetBacks