Scopes - getrailo/railo GitHub Wiki

Table of Contents

Available scopes

Local scopes

These scopes are not necessarily available between components in the same request -- in other words elements or variables in these scopes may be "out of scope" if set in one module and referred to in another.

Scope Description Notes
arguments Holds arguments that are passed to a function or CFC method
attributes Contains attributes that are passed to a custom tag
caller Refers to the scope of the calling page when a custom tag or module is called
this
thread
variables

Request scopes

These scopes persist through a single request, i.e. any code, in any module, can refer to these scopes during the life of the request:

Scope Description Notes
form Contains arguments that are received from HTML POST operations, i.e. usually form data Railo has an option to merge form and URL scopes. If this option is enabled, both scopes will contain the same items.
cgi Holds environment variables generated by the web server. CGI variables will vary according to server platform in use and browser.
request Used to store data across an entire request. Data put into the request scope will be accessible from all templates, CFCs, custom tags, etc
url Contains arguments that are received from HTTP GET operations, i.e. passed on the URL Railo has an option to merge form and URL scopes. If this option is enabled, both scopes will contain the same items.

Global scopes

These scopes persist between requests, i.e. a value can be set during one request then retrieved in a subsequent one:

Scope Description Notes
application Holds elements that relate to the application as a whole.
client Contains elements that persist indefinitely for this particular client (browser).
cookie Stores cookies. Each appears as an element in the cookie scope.
server Used to store data that is accessible from any application on a particular server.
session Holds data pertaining to the user's session.
cluster   Deprecated

What scope should I use in...?

Custom tags

Classic custom tags

The variables scope of a classic CFM-based custom tag is local to the custom tag only. It is safe to use that scope for any variables that you want to be available only within the tag itself.

CFC-based custom tags

The normal rules for CFCs apply.

Should I use scopes explicitly?

Different developers have opinions about whether it is best to explicitly write every scope, or to let Railo look for the variable in each scope, i.e.

   myVariable

vs

   variables.myVariable

Please see Using scopes explicitly in code for details.

Further information required

  • CGI scope reference
  • thisTag
⚠️ **GitHub.com Fallback** ⚠️