2 Replies Latest reply on Feb 11, 2012 1:52 AM by BKBK

    Extending App.cfc and file paths

    mike00817

      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?

        • 1. Re: Extending App.cfc and file paths
          BKBK Adobe Community Professional & MVP

          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>

          • 2. Re: Extending App.cfc and file paths
            BKBK Adobe Community Professional & MVP

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

             

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