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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why doesn´t change the value of the Application variables?

Status
Not open for further replies.

colosoderada

Programmer
Sep 14, 2000
26
ES
How can I make a global variable in ColdFusion?
If I have created
<!-- Application.cfm -->

<cfset APPLICATION.Identificador =&quot;1&quot;>
<cfset APPLICATION.CategoriaUsuario=&quot;5&quot;>

<!-- In other page for example Ad.01 -->

variables.categoria = 10
variables.idusuario = 20

<cfset APPLICATION.CategoriaUsuario='#variables.categoria#'>
<cfset APPLICATION.Identificador ='#variables.idusuario#'>

I want change the values of my variables.

APPLICATION.CategoriaUsuario = 10
APPLICATION.Identificador = 20

If I´m in the pages Ad.01 and I do this

<cfoutput>#Application.Identificador#</cfoutput>
<cfoutput>#Application.CategoriaUsuario#</cfoutput>

I obtain the correct value (I think that I have change the value of the applications variables).

APPLICATION.CategoriaUsuario = 10
APPLICATION.Identificador = 20

But when I change to another pages for instance Ad.02 and
I make this

<cfoutput>#Application.Identificador#</cfoutput>
<cfoutput>#Application.CategoriaUsuario#</cfoutput>

The values of the variables are the initial values

APPLICATION.Identificador =&quot;1&quot;
APPLICATION.CategoriaUsuario=&quot;5&quot;

Why???? The variables hasn´t change their values.

APPLICATION.CategoriaUsuario = 10
APPLICATION.Identificador = 20

How can I change the value of my variables?

Thank you very much.
Sorry for my english. I´m from Spain
 
Aha.

You know that every time any *.cfm page is called the Application.cfm is run.

What you are seeing is that you can change the Application.Category variable to=10 but on the next page, the Application variable is being RE-Set to 1

You don't need to <cfset> your Application.Category value on your Application.cfm page....

Try:

<!---Application.cfm--->
<cflock scope=&quot;APPLICATION&quot; type=&quot;EXCLUSIVE&quot; timeout=&quot;10&quot;>
<cfif Not isDefined('Application.Category')>
<cfset Application.Category=1>
</cfif>
</cflock>

Then:
<!---Page1.cfm--->
<cflock scope=&quot;APPLICATION&quot; type=&quot;EXCLUSIVE&quot; timeout=&quot;10&quot;>
<cfset Application.Category=10>
</cflock>


There is a good example of building an Application scoped array in CF here if you are interested.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top