coldfusion problem about onRequest method in Application.cfc

5 views
Skip to first unread message

YouSui

unread,
Jul 9, 2009, 4:27:49 AM7/9/09
to CFCDev


hi everyone, 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.

Kevan Stannard

unread,
Jul 10, 2009, 4:54:53 PM7/10/09
to cfc...@googlegroups.com
YouSui, no idea why "this" is not set when onRequest() is not present, but if you need access to your application object you are probably better off doing something like this:

<cffunction name="onApplicationStart" returnType="boolean" output="false">
    <cfset application.app = this>
    <cfreturn true>
</cffunction>

And in your test.cfm

<cfdump var="#application.app#">




2009/7/9 YouSui <you...@gmail.com>

Alpino, Justin

unread,
Jul 10, 2009, 5:14:36 PM7/10/09
to cfc...@googlegroups.com
Hi YouSui,
 
The reason why "this" doesn't exist when you remove the onRequestStart() method is because your 'test.cfm' is no longer being executed within the context of the (application) CFC. The <cfinclude> in the onRequest() method enables 'test.cfm' to reference any of the internal/private or publicly accessible attributes of the CFC.

Justin

"The sender believes that this E-mail and any attachments were free of any harmful and malicious code or defects when sent. The sender is not liable for any loss or damage arising in any way from this message or its attachments.

Confidentiality Note: This e-mail is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. Dissemination, distribution or copying of this e-mail or the information herein by anyone other than the intended recipient, is prohibited. If you have received this e-mail in error, please inform the sender, and destroy the original message and all copies."

rex

unread,
Jul 10, 2009, 1:44:50 PM7/10/09
to cfc...@googlegroups.com
The VARIABLES scope is the default scope for an unscoped variable, and
is shared with the cfincluded page that is called by the onRequest
method. The THIS scope only exists in a CFC or in a method of the CFC.
Since the cfinclude is called in a method, then the THIS scope is
available in the cfincluded page.

When there is no onRequest method, the page is just executed, and the
called page, test.cfm, does not have access to any of the cfc variables,
so VARIABLES scope is empty, and the THIS scope does not exist.
Reply all
Reply to author
Forward
0 new messages