1
votes

i was blocked by a coldfusion problem, any suggestions are appreciated. now lemme decribe my problem.


i have an Application.cfc in my website root, the content in it is as follows:

<cfcomponent output="false">
    <cffunction name="onRequest" returnType="void">
        <cfargument name="thePage" type="string" required="true">
        <cfinclude template="#arguments.thePage#">
    </cffunction>
</cfcomponent>

and also i have a cfm template of which the name is test.cfm, it's content is listed as follows:

<cfdump var="#variables.this#"><br /><br /><br /><br /><br /><br />
<cfdump var="#this#">

now if you request the test.cfm, everything is ok, but when i delete the onRequest method in Application.cfc and request test.cfm again, it complaints that "Element THIS is undefined in VARIABLES. ", i don't know why, can anybody explain it? great thanks.

ps:

you can add as many functions into Application.cfc, such as onSessionStart, onSessionEnd, onApplicationStart, onApplicationEnd..., but if there is not a onRequest method, you request test.cfm and get error. i just don't know why.

2

2 Answers

7
votes

It's because the this scope refers to a cfc instance. When you include test.cfm from within application.cfc this refers to the application.cfc instance. When you call test.cfm directly this does not exist because the request did not go through application.cfc, so you're not inside a cfc instance.

Not sure what you were trying to do, but you probably don't want to use this outside of a cfc. If you want to dump the application scope from test.cfm just do this instead:

<cfdump var="#application#"/>
3
votes

Returning true from the onRequestStart method will load the page for you. As dwb stated your 'this' is referring to to the Application.cfc because you have included it from within one of the methods. If you need to refer to the Application use the application scope not 'this', unless you really are inside of the Application.cfc.