Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request variables 1

Status
Not open for further replies.

calista

Programmer
Joined
Jan 24, 2001
Messages
545
Location
US
Could someone please explain to me what the "Request" variable scope is? This is the documentation I found:

"Used to hold data that must be available for the duration of one HTTP request. The Request scope is available to all pages, including custom tags and nested custom tags, that are processed in response to the request.
This scope is useful for nested (child/parent) tags. This scope can often be used in place of the Application scope, to avoid the need for locking variables. Several chapters discuss using the Request scope."

I think the part I'm not understanding is: What is an HTTP request? I assume it's different from a page request, because that would be the local variable scope.

Thanks! Calista :-X
Jedi Knight,
Champion of the Force
 
An HTTP request is a request made by the hypertext transfer protocol... :)

Basically any variable you set in response to that request...

<CFSET test=&quot;go&quot;>

This is only available to application.cfm and the page executing, all CFINCLUDED pages and onrequestend.cfm...

<CFSET request.test=&quot;go&quot;>

This is available to all of the above including custom tags... But a variable set for Bob's request will not show up for Joe's Request...

Never fear though, if you've written an application and need to access those variables from a custom tag and they're not in the request scope, another scope will help us...

<CFSET caller.test=&quot;go&quot;>

This sets or gets a variable from the calling page... gets tricky though if its a nested custom tag..

Does this help?

Tony
 
http request refers to the page that is about to be processed and served to the client;
the difference is that if you scope the application variable at the begining of the template as 'variables', those variables are available throughout the template but if you try to access it in the custom tag within that template, you will receive and error;
if you store it in the 'request' scope, you can access it from the custom tag without having to use the cflock tag and store it in the 'variables' for that tag only;

here is another tip: I'll take it that you declare the application and session variables in the application.cfm template; usually that means that you are ready to use a lot of cflocks in order to make those variables available throughout the template;
let's say that in the application.cfm template you have used this to set session variable:

<cflock scope=&quot;session&quot; timeout=&quot;30&quot; throwontimeout=&quot;No&quot; type=&quot;exclusive&quot;>

<cfscript>
session.stClientInfo = StructNew();
session.stClientInfo[&quot;sBrowser&quot;] = browser;
session.stClientInfo[&quot;sBrowserVersion&quot;] = ver;
</cfscript>
</cflock>


at the begining of the template use this to loop through the structure and scope all the values in the request scope:

<cflock scope=&quot;session&quot; timeout=&quot;30&quot; throwontimeout=&quot;No&quot; type=&quot;readonly&quot;>
<cfloop collection=&quot;#session.stClientInfo#&quot; item=&quot;i&quot;>
<cfscript>
&quot;request.#i#&quot; = session.stClientInfo[&quot;#i#&quot;];
</cfscript>
</cfloop>
</cflock>


finally, anywhere in the template that you are about to execute, you can use the following to access the variables (even from the custom tags); that eliminates need to use any more cflocks for the entire template

<cfoutput>
#request.sBrowser#<br>
#request.sBrowserVersion#
</cfoutput>

:) Sylvano
dsylvano@hotmail.com
 
Thanks,Tony. I'm still not clear on what an HTTP request is. Who or what is making the request? The user? The server? The application? At what point in time does this occur? A request variable must persist longer than one page request, so how long is that? How does this differ from a session? Calista :-X
Jedi Knight,
Champion of the Force
 
the client is making a request for a page via http protocol - shorter, he is making a http request

the http request starts when the client makes a request for a page to the web server; the web server will pass that request to the cf application server; cf will first execute the application.cfm template and then will start parsing the HTML that will be returned to the client; the request scope is available from when the application.cfm is executed until/if the OnRequestedEnd.cfm is executed;
when next http request is made the request scoped variables are lost and you have to set them again Sylvano
dsylvano@hotmail.com
 
OK, so a request variable exists in the template in which it was created and any custom tags or objects that template might call? And, it is it's ability to be available to a custom tag that differentiates it from a local variable? Calista :-X
Jedi Knight,
Champion of the Force
 
you got it. the request scope will make a variable available to the entire page request by the browser; because the scope is the entire page request, the values are carried through to nested tags, such as custom tags; so, instead of continually passing the same value to custom tags, you put in the request scope;
a great place to set these requst scope variables is in the application.cfm template Sylvano
dsylvano@hotmail.com
 
Thanks! Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top