Skip to main content
March 26, 2010
Answered

Can't access values in 'this' structure

  • March 26, 2010
  • 1 reply
  • 2152 views

-thanksok, this is really strange....

hers's my application.cfc

<cfcomponent>
    <cfscript>
        this.name = "wg234rf6u";
        this.applicationTimeout = createTimeSpan(0,2,0,0);
        this.clientmanagement= "yes";
        this.loginstorage = "session" ;
        this.sessionmanagement = "yes";
        this.sessiontimeout = createTimeSpan(0,0,20,0);
        this.setClientCookies = "yes";
        this.setDomainCookies = "yes";
        this.scriptProtect = "all";
        this.mappings["/MenuPath"] = getDirectoryFromPath(getCurrentTemplatePath())&'Assets/XHTML/';

    </cfscript>
   
    <cffunction name="onApplicationStart" output="false" >
        <cfscript>
            application.dsn = "_mydsn_";
            application.url = "_myurl_";
        </cfscript>
    </cffunction>
   
    <cffunction name="onSessionStart" output="false" >
        <cfparam name="session.validation_errors" default="" />
        <cfparam name="session.message" default="" />
        <cfparam name="session.start" default="true" />
       
        <cfinclude template="./Assets/XHTML/functions.cfm" />
           
        <cfset #setSessionFormDefaults()# />
       
       
    </cffunction>
    <cffunction name="onrequestend" output="true" >
        <cfdump var="#this#" />
    </cffunction>
</cfcomponent>

I CAN dump the 'this' structure in the application.cfm and ONLY the application.cfm, no other file, not even if I were to put a file containing:

<cfouptut>

     <cfdump var="#this#" />

</cfoutput>

right besides application.cfc, I get a "Variable  THIS is undefined."error....

- this works on 3 other sites on the same server

- I have restarted both apache & CFMX

- there are no other cfm files in the site, just the application and my test file [so the "this" structure is not being overwritten]

- I can dump any other variable scope

ANY one have any ideas what the heck is going on here????

-thanks

-sean

This topic has been closed for replies.
Correct answer Adam Cameron.

sean69 wrote:

the Application.cfc is found & it is running but variables are not available outside of the application.cfc template!

-hum?

I am not sure they are expected to be available... At least I have never tried to access them in this manner.


No, they're not.  Application.cfc is just a CFC, so its VARIABLES are not exposed to the outside world.  That's how CFCs work.  And there's no actual instance of Application.cfc available to reference, so THIS-scoped variables are accessible either: one needs an instantiated object to be able to access its THIS-scoped variables,eg:

<cfset myObj = createObject("component", "myCfc")>

<cfoutput>#myObj.myThisScopedVariable#</cfoutput>

If there's no instance, there's no reference to use.

However.  If one implements template handling via the onRequest() method, then the template can be simply included, so is "internal" to the instance of Application.cfc currently running, so THIS and VARIABLES scoped variables are indeed available to the template being executed.

--

Adam

1 reply

ilssac
Inspiring
March 26, 2010

The 'this' structure is not a standalone structure like 'variables', 'session' or 'form'.  It is the public instance data of a component object.

This may be more clearly shown with a basic compoent of your own design.

testThis.cfc

<cfcomponent>

  <cfscript>

    this.foo = 'bar';

    this.name = 'george';

  </cfscript>

</cfcomponent>

outputThis.cfm

<cfset myObj = createObject("component","testThis")>

<cfdump var="#myObj#">

When you do this you will see the 'this' fields are public parameters of your object.  I.E. myObj.foo and myObj.name.

I think, but I am not sure, that if you dump the Application scope you may see the values set in the this scope inside the Application.cfc.

March 26, 2010

no -it's not I understand that, but I can dump the 'this' structure on any other site BUT this one....

[the entire structure shows up under MAPPINGS if you try to dump the application scopenormally, but not this site!!]

I've done sopme more testing, any structure I define inside the application.cfc [in onrequest, requestnd etc...]  is not avalable outside the application CFC!?

this came about trying to define a directory mapping, this.mappings['/MyPath']  breaks horribly.

the site has a CGI application running on it, but that should not be coming into play as it is all called from *.html pages

if I place a test.cfm with one line <cfdum var="#this#" /> I can't dump the structure AND the cgi should not be in play as the .html template wsa never called [and no .htaccess doing anything funky]

also curiously enough, if I turn up debugging all the way, none of the variable scopes will dump, I have to dump them manually.

some thing odd is going on

-thoughts?

PS> your test works btw.

ilssac
Inspiring
March 26, 2010

Is that file actually named "application.cfc" and not "Application.cfc"?   Note the case difference in the name.

And are you on a nix flavored system like it sounds?

If you are on a nix flavored system and the file name is "application.cfc" with the lower case a, then the file is not being ran.  ColdFusion actually looks for a file with a capitol 'A' as in "Application.cfc".