Skip to main content
Participant
February 2, 2012
Question

Extending App.cfc and file paths

  • February 2, 2012
  • 2 replies
  • 644 views

I have a setup where I grab the root path of my application in app.cfc using GetDirectoryFromPath(GetCurrentTemplatePath()) and set it in the application scope through OnApplicationStart. This works great for most of the site, but I have one subfolder where I've extended app.cfc to add a login script to OnRequestStart.  The problem I'm having is if the application starts up from that subfolder, the extended app.cfc sets the root path from the subfolder instead of the root folder where the original app.cfc is located.

Anyone know a way to fix this?

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
February 11, 2012

Another idea: hard-code it in onApplicationStart as an application constant, for example

<cfset application.path = "c:\ColdFusion9\wwwroot\mySite\myDir\index.cfm">

BKBK
Community Expert
Community Expert
February 4, 2012

I do believe that that is the expected behaviour. ColdFusion invokes the system functions relative to the caller.

That, in fact, also suggests a possible solution. Create the following component in the same directory as the parent Application file.

Path.cfc

<cfcomponent output="no">

    <cffunction name="getPath" output="no" returntype="string">

        <cfreturn GetDirectoryFromPath(GetCurrentTemplatePath())>

    </cffunction>

</cfcomponent>

Then modify the code in the parent Application.cfc to call the functions relative to the Path object, like this

<cfcomponent>   

    <cffunction name="onApplicationStart" returntype="boolean">       

        <cfset application.path = createobject("component","Path").getPath()>

        <cfreturn true>

     </cffunction>

</cfcomponent>