Results 1 to 3 of 3

Thread: coldfusion link problem

  1. #1
    Join Date
    Jun 2012
    Posts
    2

    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
    Code:
    <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
    Code:
    <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
    Posts
    99

    Default Need to set Application variables in onApplicationStart method

    Hi,

    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:
    Code:
    <cfcomponent output="false">
    	<cfset THIS.Name = "cftestapp" />
    
    	<cffunction name="onApplicationStart" returnType="boolean" output="false">
    	   <cfset application.basePath = "#GetDirectoryFromPath(CGI.SCRIPT_NAME)#" />
    
    	   <cfreturn true>
    	</cffunction>
    </cfcomponent>
    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
    Posts
    2

    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
  •