21. What is Scope Variables?
A variable's scope is
determined by its origin. The scope determines a number of properties
about the variable, such as its life span, timeout, and storage
location, and therefore, how it can be used.
22. What is the different type of Scope variables?
| Scope | Description |
|---|---|
| Application | Contains variables that are associated with one, named application on a server. The cfapplication tag name attribute or the Application.cfc This.name variable setting specifies the application name. |
| Arguments | Variables passed in a call to a user-defined function or ColdFusion component method. |
| Attributes | Used only in custom tag pages and threads. Contains the values passed by the calling page or cfthread tag in the tag's attributes. |
| Caller | Used only in custom tag pages. The custom tag's Caller scope is a reference to the calling page's Variables scope. Any variables that you create or change in the custom tag page using the Caller scope are visible in the calling page's Variables scope. |
| CGI | Contains environment variables identifying the context in which a page was requested. The variables available depend on the browser and server software. |
| Client | Contains variables that are associated with one client. Client variables let you maintain state as a user moves from page to page in an application, and are available across browser sessions. By default, Client variables are stored in the system registry, but you can store them in a cookie or a database. Client variables cannot be complex data types and can include periods in their names. |
| Cookie | Contains variables maintained in a user's browser as cookies. Cookies are typically stored in a file on the browser, so they are available across browser sessions and applications. You can create memory-only Cookie variables, which are not available after the user closes the browser. Cookie scope variable names can include periods. |
| Flash | Variables sent by a Flash movie to ColdFusion and returned by ColdFusion to the movie. |
| Form | Contains variables passed from a Form page to its action page as the result of submitting the form. (If you use the HTML form tag, you must use method="post".) |
| function local | Contains variables that are declared inside a user-defined function or ColdFusion component method and exist only while a function executes. |
| Request | 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. |
| Server | Contains variables that are associated with the current ColdFusion server. This scope lets you define variables that are available to all your ColdFusion pages, across multiple applications. |
| Session | Contains variables that are associated with one client and persist only as long as the client maintains a session. They are stored in the server's memory and can be set to time out after a period of inactivity. |
| This | Exists only in ColdFusion components or cffunction tags that are part of a containing object such as a ColdFusion Struct. Exists for the duration of the component instance or containing object. Data in the This scope is accessible from outside the component or container by using the instance or object name as a prefix. |
| ThisTag | Used only in custom tag pages. The ThisTag scope is active for the current invocation of the tag. If a custom tag contains a nested tag, any ThisTag scope values you set before calling the nested tag are preserved when the nested tag returns to the calling tag. The ThisTag scope includes three built-in variables that identify the tag's execution mode, contain the tag's generated contents, and indicate whether the tag has an end tag. A nested custom tag can use the cfassociate tag to return values to the calling tag's ThisTag scope. |
| Thread | Variables that are created and changed inside a ColdFusion thread, but can be read by all code on the page that creates the thread. Each thread has a Thread scope that is a subscope of a cfthread scope. |
| thread local | Variables that are available only within a ColdFusion thread. |
| URL | Contains parameters passed to the current page in the URL that is used to call it. The parameters are appended to the URL in the format ?variablename = value[&variablename=value...]; for example www.MyCompany.com/inputpage.cfm?productCode=A12CD1510&quantity=3. Note: If a URL includes multiple parameters with the same name, the resulting variable in the ColdFusion URL scope consists of all parameter values separated by commas. For example, a URL of the form http://localhost/urlparamtest.cfm? param=1¶m=2¶m=3 results in a URL.param variable value of 1,2,3 on the ColdFusion page. |
| Variables (local) | The default scope for variables of any type that are created with the cfset and cfparam tags. A local variable is available only on the page on which it is created and any included pages (see also the Caller scope). |
23. What is Application Variables? How can you clear these variables?
These are special scope variables that are available to all pages in an application for all clients.
Data is stored in application server memory.
You must use the Application scope prefix in the variable name.
<!--- To delete all application variables--->
<cfset StructClear(Application)>
<!--- To delete a particular variable in session --->
<cfset StructDelete(Application, "varName")>
24. What is Session Variables? How can you clear these variables?
These are special scope variables that are available for a single client browser for a single browser session in an application.
Data is stored in application server memory.
You must use the Session scope prefix in the variable name.
<!--- To delete all session variables --->
<cfset StructClear(Session)>
<!--- To delete a particular variable in session --->
<cfset StructDelete(Session, "varName")>
25. How can you list out all the Session variables in an Application?
use cfdump to show entire session value in Development environment.
<cfdump var="#session#">
Session variables are in stored in structure format. So you loop through the collection to show the session variables.
<cfoutput><cfloop collection=#session# item="key"> #key# : #structFind(session,key)#<br /> </cfloop></cfoutput>
26. How can you delete the session variables?
<!--- To delete all session variables --->
<cfset StructClear(Session)>
<!--- To delete a particular variable in session --->
<cfset StructDelete(Session, "varName")>
27. What is a client variable?
These are special scope variables that are available for a single client browser over multiple browser sessions in an application.
Data is stored as cookies, database entries, or Registry values.
No need to use the Client scope prefix in the variable name
Value must be simple variables. Can not be arrays, structures, query objects, or other objects.
28. What is the default storage for client variable?
client variables stored in registry, database or in client cookie.By
default, ColdFusion stores this in the Registry.it is more appropriate
to store the information as client cookies or in a SQL database.
29. What is URL token?
Combination of CFID & CFTOKEN is called as urltoken. If user disabled the browser cookie, It is used to track a user's browser session.
30. What is Cookie Variables?
Cookies are server specific simply stored variables stored in files in the browser's file system. It used to track state maintenance(browser session) of a user.
31. What is the difference between Client and Session variables?
Session
variables can be used to dump complex data structures like arrays and
structures.But client variable are used only in case of simple
variables.
32. What is Structure? What are the different functions in Structure?
ColdFusion
structures consist of key-value pairs. Structures let you build a
collection of related variables that are grouped under a single name. A
structure's key must be a string. The values associated with the key
can be any valid ColdFusion value or object. It can be a string or
integer, or a complex object such as an array or another structure.
Because structures can contain any kind of data they provide a very
powerful and flexible mechanism for representing complex data. check Structure functions here.
33. What is the difference between Structure and Array?
In
structure one can combine variables of different datatype in to a
common data type Whereas arrays are sequentially stored values of the
same datatype.
34. How can you set common footer?
Using cfinclude, we can
include footer file in all pages. We can OnRequestEnd.cfm file or
OnRequestEnd method in Application.cfc also to include footer file.
35. What is OnRequestEnd.cfm? When it will execute?
Just
as the Application.cfm page runs before the code on an application
page, an OnRequestEnd.cfm page runs, if it exists, after each
application page in the same application.The OnRequestEnd.cfm page must
be in the same directory as the Application.cfm page ColdFusion uses
for the current page. ColdFusion does not search beyond that directory,
so it does not run an OnRequestEnd.cfm page that resides in another
directory.The OnRequestEnd.cfm page does not run if there is an error
or an exception on the application page, or if the application page
executes the cfabort or cfexit tag. Page flow given below
Application.cfm -> CFM page -> OnRequestEnd.cfm
36. Can we have multiple OnRequestEnd.cfm in an Application? How its works?
Yes,
We can have. The OnRequestEnd.cfm page must be in the same directory as
the Application.cfm page ColdFusion uses for the current page.
ColdFusion does not search beyond that directory
39. Where we can place the custom tag?
Custom tags can be stored in any of the following locations. ColdFusion will search for them in the order listed.
In the same directory as the calling page - while this is easy for
demonstration purposes, it's not very practical, as it means that the
custom tag is only available within that directory.
In a
directory (or subdirectory of a directory) specified in ColdFusion
Administrator under Extensions -> Custom Tag Paths.
In the cfusion/CustomTags directory or one of its subdirectories.
40. What are the different ways to call custom tag?
using cf_ filename of custom tag
using cfmodule tag
using cfimport tag










Recent Comments