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

Include's relative link problem

New Here ,
May 24, 2012 May 24, 2012

I am doing this on dreamweaver cs4 on my application.cfm page I have the following script 

 

On the page that i'm using the include I have down      I have tried that and several variations and I keep getting an error which says Element BASEPATH is undefined in APPLICATION.  how can i resolve this? 

2.5K
Translate
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
LEGEND ,
May 24, 2012 May 24, 2012

Your post appears to be incomplete.

Translate
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
New Here ,
May 24, 2012 May 24, 2012

oh ok i just noticed basically my application.cfm code is

"<cfapplication>

<cfset application.basePath= GetDirectoryFromPath(CGI.SCRIPT_NAME)>

</cfapplication>"

now in my include page I have

"<cfinclude template="#application.basePath#master.cfm" />"

and that is when I keep getting the error message element basepath is undefined in application

Translate
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
LEGEND ,
May 24, 2012 May 24, 2012

Right before that line, cfdump your application scope to see if the variable is there.

The problem might be that your application does not have a name.

Translate
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
New Here ,
May 24, 2012 May 24, 2012

I did that I added a name to the application.cfm "<cfset this.name=testname>" and then put "<cfdump var="#application#">" before the include and the application name was there and I enabled robust debugging which said that the error is from the <include template="#application.basePath#master.cfm" /> is there any other method to include a relative link that might work..

Translate
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 ,
May 25, 2012 May 25, 2012

johnny_perez_new wrote:

I did that I added a name to the application.cfm "<cfset this.name=testname>" and then put "<cfdump var="#application#">" before the include and the application name was there and I enabled robust debugging which said that the error is from the <include template="#application.basePath#master.cfm" /> is there any other method to include a relative link that might work..

Ensure the name of your application file starts with capital A. Also, let the cfapplication tag at least have the following attributes:

<cfapplication name="testname"

    sessionmanagement="Yes"

    sessiontimeout="#createTimeSpan(0,0,20,0)#"

    applicationtimeout="#createTimeSpan(1,0,0,0)#">

Translate
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
LEGEND ,
May 25, 2012 May 25, 2012

Ensure the name of your application file starts with capital A. Also, let the cfapplication tag at least have the following attributes:

<cfapplication name="testname"

    sessionmanagement="Yes"

    sessiontimeout="#createTimeSpan(0,0,20,0)#"

    applicationtimeout="#createTimeSpan(1,0,0,0)#">

I think your subsequent post is the one that's important, but just on this one: the only attribute one needs is the name.  Session activation is only needed if one needs sessions, and the timeouts are only needed if they vary from what's in CFAdmin already.

Strictly speaking even the name is not required, but it's bad form not to have one.

But it's the improper use of <cfapplication> as a nestable tag that's most likely the problem here.

--

Adam

Translate
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 ,
May 25, 2012 May 25, 2012

Adam Cameron. wrote:


I think your subsequent post is the one that's important, but just on this one: the only attribute one needs is the name.  Session activation is only needed if one needs sessions, and the timeouts are only needed if they vary from what's in CFAdmin already.

Strictly speaking even the name is not required, but it's bad form not to have one.

All true. However, I was thinking of something else. As Johnny_Perez_New seems to be unfamilar with cfapplication, I wished to introduce the tag with its most commonly used attributes.

Translate
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
LEGEND ,
May 25, 2012 May 25, 2012

Your cfdump shows that application.basePath is not being set by your Application.cfm page.  It's just as well.  Your approach makes it possible for user A to set the variable, user B to change it, and then user A uses the wrong value.

I suggest changing Application.cfm to Application.cfc.  Then set your variable in the OnRequestStart function.  Also, don't make it an application variable.  Off the top of my head I can't think of the most appropriate scope, but you should be able to figure it out.

Translate
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 ,
May 25, 2012 May 25, 2012

Dan Bracuk wrote:

Your cfdump shows that application.basePath is not being set by your Application.cfm page.  It's just as well.  Your approach makes it possible for user A to set the variable, user B to change it, and then user A uses the wrong value.

That isn't the case here, Dan. Application.basePath is a CGI variable which, we may assume, cannot be changed by the user.

Translate
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
LEGEND ,
May 26, 2012 May 26, 2012

Your cfdump shows that application.basePath is not being set by your Application.cfm page.  It's just as well.  Your approach makes it possible for user A to set the variable, user B to change it, and then user A uses the wrong value.

That isn't the case here, Dan. Application.basePath is a CGI variable which, we may assume, cannot be changed by the user.

I see what Dan's on about.

Say a user hits /some/path/to/a/file.cfm, then application.basePath will be /some/path/to/a/.  Now a different user hits /some/path/to/a/different/file.cfm, the variable will be /some/path/to/a/different/.

This is not the sort of thing one wants setting on a request by request basis, which is what's gonna happen in Application.cfm

The variable should not:

a) be set via a request-centric setting such as a CGI-scoped variable

b) reset every request.

Surely the base path is known to the application code, so it should just be hard-coded?

I'd also recommend using Application.cfc over Application.cfm.  Whilst not specifically stated, Appliction.cfm is an obsolete approach to application / request management.

--

Adam

Translate
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 ,
May 26, 2012 May 26, 2012

Adam Cameron. wrote:

Your cfdump shows that application.basePath is not being set by your Application.cfm page.  It's just as well.  Your approach makes it possible for user A to set the variable, user B to change it, and then user A uses the wrong value.

That isn't the case here, Dan. Application.basePath is a CGI variable which, we may assume, cannot be changed by the user.

I see what Dan's on about.

Say a user hits /some/path/to/a/file.cfm, then application.basePath will be /some/path/to/a/.  Now a different user hits /some/path/to/a/different/file.cfm, the variable will be /some/path/to/a/different/.

If the applicationtimeout value is substantial then, as long as the application doesn't restart, the variable will remain unchanged. However, the first user to open the application determines the value for subsequent users. So there's no escaping the argument from you and Dan. I sincerely overlooked the intricacies.

Translate
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
LEGEND ,
May 26, 2012 May 26, 2012

The code in question is a , and it's bring called every request.

--

Adam

Translate
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
LEGEND ,
May 27, 2012 May 27, 2012

Adam Cameron. wrote:

The code in question is a , and it's bring called every request.

Oh FFS these forums are pathetic.

What I actually posted was this:

The code in question is a <cfset> in Application.cfm. The variable will be re-set every request. Application.cfm had no special application-centric properties (it's misnamed, it should be called OnRequestStart.cfm), so it doesn't matter about application timeouts: a <cfset> is a <cfset>, and it's [being] called every request.


I shouldn't have attempted to respond by email, I guess.

--

Adam

Translate
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 ,
May 27, 2012 May 27, 2012

Adam Cameron. wrote:

What I actually posted was this:

The code in question is a <cfset> in Application.cfm. The variable will be re-set every request. Application.cfm had no special application-centric properties (it's misnamed, it should be called OnRequestStart.cfm), so it doesn't matter about application timeouts: a <cfset> is a <cfset>, and it's [being] called every request.


I shouldn't have attempted to respond by email, I guess.


No problem: it was obvious something went wrong on the wire.

Thanks for pointing that out. I can now see the confusion arose from an omission on my part. By the time I wrote my last post, at least 2 recommendations had been made to the poster to switch to Application.cfc. (which I incidentally also strongly support). I therefore implicitly had Application.cfc and onApplicationStart in mind. The assumption is therefore that the application variable is initialized in onApplicationStart.

Otherwise my point about a restart becomes absurd, to say the least. I hope this explanation clarifies that passage. Even if you switch to Application.cfc, initializing the application variable in onApplicationStart, you still won't escape the dilemma of one user setting a path for others.

Translate
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 ,
May 27, 2012 May 27, 2012
LATEST

@Johnny_Perez_New

You could start with a basic Application.cfc like the following, and fill in the details later where needed:

<cfcomponent>

    <cfscript>

        this.name = "testname";

        this.applicationTimeout = "#createTimespan(1,0,0,0)#";

        this.sessionManagement = "true";

        this.sessionTimeout = "#createTimeSpan(0,0,20,0)#";

    </cfscript>

   

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

            <!--- Initialize application variables here --->

        <cfreturn true>

     </cffunction>

    

    <cffunction name="onSessionStart">

      

        </cffunction>

    <cffunction name="onRequestStart">

     <cfargument name = "targetPage" type="String" required="yes">

          <!--- Initialize variables here that you wish to be available to every request --->

      <!--- This is therefore not the place to set application or session variables --->

     </cffunction>

    <cffunction name="onRequestEnd">

       <cfargument type="String" name = "targetTemplate" required="yes">

   

    </cffunction>

    <cffunction name="onSessionEnd">

       <cfargument name = "SessionScope" required="yes">

       <cfargument name = "AppScope" required="yes">

      

          <cflog file="#This.Name#" type="Information" text="Session: #arguments.SessionScope.sessionid# ended">

    </cffunction>

     <cffunction name="onApplicationEnd">

       <cfargument name="ApplicationScope" required="yes">  

      <cflog file="#This.Name#" type="Information"

          text="Application #ApplicationScope.applicationname# Ended">

    </cffunction>

</cfcomponent>

Translate
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 ,
May 25, 2012 May 25, 2012

<cfapplication>

<cfset application.basePath= GetDirectoryFromPath(CGI.SCRIPT_NAME)>

</cfapplication>

I suspect it is incorrect to use the cfapplication tag in this way. See my previous example.

Translate
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