• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Extending App.cfc and file paths

New Here ,
Feb 01, 2012 Feb 01, 2012

Copy link to clipboard

Copied

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?

TOPICS
Advanced techniques

Views

600

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2012 Feb 04, 2012

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2012 Feb 11, 2012

Copy link to clipboard

Copied

LATEST

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

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation