Copy link to clipboard
Copied
-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
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
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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".
Copy link to clipboard
Copied
yes - it is absolutely with a capital "A" [why they did tht is beyond me - but... whatever] sorry - fat fingers.
yes - linux [centos] apache 2, under plesk*, and like I said I have no .htaccess nor have I done anything odd to the httpd.conf or includes
[*technically plesk does not know CFMX is installed - it's sort of standalone - but I have about 20 sites using CF in one form or another running on the server with no weirdness ]
the only thing different here is that cgi application .... it's a compiled C#[#?] app living in the cgi-bin, but not called through any of this testing... you think it could be interfering in any fasion?
-sean
Copy link to clipboard
Copied
just ran another test, I removed everything from cgi-bin + all other files BUT Application.cfc & my info.cfm .... restarte apache & CF ... still same issue.
hum?
Copy link to clipboard
Copied
Don't know, I'm running out of ideas without having access to your system so I could start poking sticks at it.
My last resort would be to go absolutely minimalist with your last test. Create a new Appliaiton.cfc file with just a simple this.name in it and see if that works. Nail down if it is all Appliaiton.cfc files being ignored or just this specific one for some unknown reason.
Copy link to clipboard
Copied
So this is what I did,
Application.cfc:
<cfcomponent>
<cfscript>
this.mappings["/MenuPath"] = getDirectoryFromPath(getCurrentTemplatePath())&'Assets/XHTML/';
myvar = 'this is a test';
writeoutput(this.mappings['/MenuPath']);
writeoutput(myvar);
</cfscript>
</cfcomponent>
info.cfm:
<cfoutput>
<cfscript>
writeoutput(this.mappings['/MenuPath']);
writeoutput(myvar);
</cfscript>
</cfoutput>
and I can info.cfm, I get this back:
/var/www/vhosts/_domain_/httpdocs/Assets/XHTML/this is a test
+ an error "Element MAPPINGS is undefined in THIS.
If I switch them around the local variable is not found either. so:
the Application.cfc is found & it is running but variables are not available outside of the application.cfc template!
-hum?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
They are, I have another site on the same server and this works:
the page:
<cfoutput><h1 class="image gallery"><span>Image Gallery</span></h1>
<cfdirectory action="list" directory="#this.mappings["/GalleryMapping"]#" name="gallery" />
<cfset group = 0 /><cfloop query="gallery">
<cfdirectory action="list" directory="#this.mappings["/GalleryMapping"]##gallery.name#" name="thumb" />
<h2>#gallery.name#</h2>
<ul class="gallery">
<cfloop query="thumb">
<cfif thumb.name is not "thumbs.db">
<li>
<a href="/Assets/Images/Gallery/Images/#thumb.name#" rel="#group#" title="Title">
<img src="/Assets/Images/Gallery/Thumbs/#gallery.name#/#thumb.name#" width="100" height="100" /></a>
</li>
</cfif>
</cfloop>
<cfset group++ />
</ul>
</cfloop>
#testvar#
</cfoutput>
the Application.cfc:
<cfcomponent>
<cfscript> this.name = "awefw32-5267gh"; this.applicationTimeout = createTimeSpan(0,2,0,0); this.clientmanagement= "no"; this.loginstorage = "session" ; this.sessionmanagement = "yes"; this.sessiontimeout = createTimeSpan(0,0,20,0); this.setClientCookies = "no"; this.setDomainCookies = "no"; this.scriptProtect = "all"; this.mappings["/GalleryMapping"] = getDirectoryFromPath(getCurrentTemplatePath())&'Assets/Images/Gallery/Thumbs/'; testvar = "this is a test"; </cfscript> <cffunction name="onApplicationStart" output="false" >...... etc.....
both the directory mapping & the local variable "testvar" are available on the gallery page....
-sean
Copy link to clipboard
Copied
maybe a better reply would be "how am I supposed to be accessing them,?"
Copy link to clipboard
Copied
Well, I run this code and I get the same expected error. "Mappings" is undefined in the 'This' scope.
If that code is working somewhere for you, then something else must be going on. Is this a different version of CF? Something else different about the setup?
Copy link to clipboard
Copied
sorry Ian, I guess the rest of the working cfc would have been useful here:
<cffunction name="onRequest" output="yes" >
<cfparam name="url.page" default="home" />
<cfif url.page is "">
<cfset url.page = "home" />
<cfelse>
<cfset page = "#url.page#" />
</cfif>
<cfsavecontent variable="myContent">
<cfinclude template="./index.cfm" />
</cfsavecontent>
<cfoutput>#myContent#</cfoutput>
</cffunction>
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Ahh-hahah ... *DING*
yes - the cfc/pages I am having problems with are not using any template handling, while the pages that do work are passing through and onrequest....
soooo....
this.mappings['whatever'] is not possble to use unless I pass all my templates throught the onrequest? unless I instantiate an instance of Application.cfc [??!! that doesn't sound right...]
I would have to use an application variable?
-thanks
-sean
Copy link to clipboard
Copied
Well there's nothing to stop you putting them in the application scope if you want to:
<!--- in onApplicationStart(), I guess --->
<cfset application.thisFromApplicationCfc = this>
(I've not tried it, but it should work?)
--
Adam