0
Application.cfc
Explorer
,
/t5/coldfusion-discussions/application-cfc/td-p/104413
Dec 19, 2008
Dec 19, 2008
Copy link to clipboard
Copied
In my Application.cfc file (which I started based on
something found on the web and/or in Ben Forta's WACK) the
following code seems (to me) non-useful yet deleting it causes
problems. Could someone take a shot at explaining what the
"thePage" argument does and whether it is simply a mandatory/needed
bit of code? Thanks in advance:
<!--- Run before the request is processed --->
<cffunction name="onRequestStart" returnType="boolean" output="false">
<cfargument name="thePage" type="string" required="true">
<cfreturn true>
</cffunction>
<!--- Runs before request as well, after onRequestStart --->
<cffunction name="onRequest" returnType="void">
<cfargument name="thePage" type="string" required="true">
<cfinclude template="#arguments.thePage#">
</cffunction>
<!--- Runs at end of request --->
<cffunction name="onRequestEnd" returnType="void" output="false">
<cfargument name="thePage" type="string" required="true">
</cffunction>
<!--- Run before the request is processed --->
<cffunction name="onRequestStart" returnType="boolean" output="false">
<cfargument name="thePage" type="string" required="true">
<cfreturn true>
</cffunction>
<!--- Runs before request as well, after onRequestStart --->
<cffunction name="onRequest" returnType="void">
<cfargument name="thePage" type="string" required="true">
<cfinclude template="#arguments.thePage#">
</cffunction>
<!--- Runs at end of request --->
<cffunction name="onRequestEnd" returnType="void" output="false">
<cfargument name="thePage" type="string" required="true">
</cffunction>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/coldfusion-discussions/application-cfc/m-p/104414#M10185
Dec 19, 2008
Dec 19, 2008
Copy link to clipboard
Copied
ProjectedSurplus wrote:
> explaining what the "thePage" argument does
> and whether it is simply a mandatory/needed bit of code
"thePage" represents the path of whatever page you requested. That is useful information if you want to execute code when a request event is triggered. The examples above are just that: examples. I think they are simply trying to show the correct syntax for the different request functions. With the exception of onRequest, the other functions do nothing. So you are correct in thinking they serve no additional purpose here.
> yet deleting it causes problems
Those three functions are all optional. So removing the entire _function_ should not cause problems. However, removing the argument might. For example in the code above the <cfinclude> inside onRequest is what causes the page you requested to be displayed. If you removed that argument, nothing would happen and you probably just get a blank screen.
So in summary, you do not have to use any of the request functions. But if you _do_ use them, do not remove the "thePage" argument.
> explaining what the "thePage" argument does
> and whether it is simply a mandatory/needed bit of code
"thePage" represents the path of whatever page you requested. That is useful information if you want to execute code when a request event is triggered. The examples above are just that: examples. I think they are simply trying to show the correct syntax for the different request functions. With the exception of onRequest, the other functions do nothing. So you are correct in thinking they serve no additional purpose here.
> yet deleting it causes problems
Those three functions are all optional. So removing the entire _function_ should not cause problems. However, removing the argument might. For example in the code above the <cfinclude> inside onRequest is what causes the page you requested to be displayed. If you removed that argument, nothing would happen and you probably just get a blank screen.
So in summary, you do not have to use any of the request functions. But if you _do_ use them, do not remove the "thePage" argument.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
ProjectedSurplus
AUTHOR
Explorer
,
/t5/coldfusion-discussions/application-cfc/m-p/104415#M10186
Dec 19, 2008
Dec 19, 2008
Copy link to clipboard
Copied
OK, so I deleted all three functions and everything still
seems to be working so thank you.
Could you extrapolate if possible on uses for each of the three? I assume that for example I could put an
isDefined("SESSION.auth.IsSignedIn") into onRequestStart or onRequest but currently have those in an cfif on my index page which seems more logical
Alternatively I guess I could write the IP address of each request for stats purposes or compare the IP vs. IP_used_2_sign_In to prevent cross site scripting (???) but I can't really think of any additional uses.
Could you extrapolate if possible on uses for each of the three? I assume that for example I could put an
isDefined("SESSION.auth.IsSignedIn") into onRequestStart or onRequest but currently have those in an cfif on my index page which seems more logical
Alternatively I guess I could write the IP address of each request for stats purposes or compare the IP vs. IP_used_2_sign_In to prevent cross site scripting (???) but I can't really think of any additional uses.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/application-cfc/m-p/104417#M10188
Dec 21, 2008
Dec 21, 2008
Copy link to clipboard
Copied
quote:
Originally posted by: ProjectedSurplus
Could you extrapolate if possible on uses for each of the three? I assume that for example I could put an
isDefined("SESSION.auth.IsSignedIn") into onRequestStart or onRequest but currently have those in an cfif on my index page which seems more logical
Read the WACK again for the interaction between onRequest and onRequestStart. Personally, I just use onRequestStart.
The use of onRequestStart and onRequestEnd is to execute code at the start or end of any page request in the application. The code is up to you.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/coldfusion-discussions/application-cfc/m-p/104418#M10189
Dec 22, 2008
Dec 22, 2008
Copy link to clipboard
Copied
ProjectedSurplus wrote:
> Could you extrapolate if possible on uses for each of the three? I assume
> that for example I could put an
As others have pointed out, this is well discussed in the documentation.
But I'll go ahead and give the 10 second preview.
The On{event}Start and On{event}End functions are pretty straight
forward. These events fire at the start and the end of the given
events; Application, Session, Request.
With the Request event, as well as having functions that fire when the
request Starts and Ends, there is the onReqest function. This function
actually intercepts the content of the request after ColdFusion as built
it, but before the content is returned to the web server. This provides
possible functionality such as modify the entire content before sending
it on to the client.
But there are strong caveats to intercepting the request and one should
be aware of these before doing so.
> Could you extrapolate if possible on uses for each of the three? I assume
> that for example I could put an
As others have pointed out, this is well discussed in the documentation.
But I'll go ahead and give the 10 second preview.
The On{event}Start and On{event}End functions are pretty straight
forward. These events fire at the start and the end of the given
events; Application, Session, Request.
With the Request event, as well as having functions that fire when the
request Starts and Ends, there is the onReqest function. This function
actually intercepts the content of the request after ColdFusion as built
it, but before the content is returned to the web server. This provides
possible functionality such as modify the entire content before sending
it on to the client.
But there are strong caveats to intercepting the request and one should
be aware of these before doing so.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/coldfusion-discussions/application-cfc/m-p/104416#M10187
Dec 19, 2008
Dec 19, 2008
Copy link to clipboard
Copied
There are a lot of possibilities. Though you might not need
these functions in every application.
As far as usage, there are some pretty good examples in the documentation. So rather than my re-inventing the wheel I am going to point you there ;-)
http://livedocs.adobe.com/coldfusion/7/htmldocs/00000694.htm#1190269
As far as usage, there are some pretty good examples in the documentation. So rather than my re-inventing the wheel I am going to point you there ;-)
http://livedocs.adobe.com/coldfusion/7/htmldocs/00000694.htm#1190269
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more