Results 1 to 3 of 3

Thread: coldfusion link problem

  1. #1
    Join Date
    Jun 2012

    Angry coldfusion link problem

    I am using cfinclude and having a hard time figuring out a relative path solution it says template this is my code
    application.cfc file
    <cfcomponent output="false">
    <cfset This.application.basePath=  GetDirectoryFromPath(CGI.SCRIPT_NAME) />
    Then on one of my webpages lets say index.cfm/users/userinfo.cfm i use
    <cfinclude template="#application.basePath#header.cfm">
    and i would get an error saying "Element BASEPATH is undefined in APPLICATION." I know that I can use "../" to get the template but then when i go to another webpage that is not listed on that folder i get an error also. How can i use relative path in my cfc to apply to all of the cfincludes ?

  2. #2
    Join Date
    Nov 2009

    Default Need to set Application variables in onApplicationStart method


    There are a few issues:

    1) The Application variable (basePath) needs to be set inside the onApplicationStart() method of the Application.cfc
    2) You will need to remove "this." from before "application.basePath"
    3) Because GetDirectoryFromPath() returns a String, you'll need to evaluate that string inside hashmarks, and put quotations around the evaluation of the function.

    As such, the Application.cfc should look something like this:
    <cfcomponent output="false">
    	<cfset THIS.Name = "cftestapp" />
    	<cffunction name="onApplicationStart" returnType="boolean" output="false">
    	   <cfset application.basePath = "#GetDirectoryFromPath(CGI.SCRIPT_NAME)#" />
    	   <cfreturn true>
    Then you'll want to force the Application to restart so ColdFusion will run your onApplicationStart() method.

    When I tested this, the <cfinclude> worked as expected.

    Take care!

  3. #3
    Join Date
    Jun 2012

    Default It works now

    thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts