2 Replies Latest reply on Apr 23, 2007 2:21 PM by insuractive

    dynamic session variable names

    r34220
      I need some help with setting dynamic session variables. I use the following code:
      <cfset VARIABLES[ "session."& res.system & "_Status" ] = "Unknown" /> where res.system = mysystem
      If I output say #session.mysystem_Status# I get the correct value of the variable if I try to use <cfdump var="session"> the session variable is not included in output of the cfdump. And I cant uses it in any other functions except for cfouput. If I try
      <cfif evaluate("session.#monitors [1]#_Status") eq "Unknown"> Unknown</cfif> where monitors[1] is "mysystem" I get a error that says the session variable is undefined.

      Please help :)
        • 1. Re: dynamic session variables
          Level 7
          r34220 wrote:
          > I need some help with setting dynamic session variables. I use the following
          > code:
          > <cfset VARIABLES[ "session."& res.system & "_Status" ] = "Unknown" /> where
          > res.system = mysystem
          > If I output say #session.mysystem_Status# I get the correct value of the
          > variable if I try to use <cfdump var="session"> the session variable is not
          > included in output of the cfdump. And I cant uses it in any other functions
          > except for cfouput. If I try
          > <cfif evaluate("session.#monitors [1]#_Status") eq "Unknown"> Unknown</cfif>
          > where monitors
          [1] is "mysystem" I get a error that says the session variable
          > is undefined.
          >
          > Please help :)
          >

          of course it is not defined because with <cfset VARIABLES[ "session."&
          res.system & "_Status" ] = "Unknown" /> you are setting a local
          VARIABLES scope var named "session.mysystem_Status", not a SESSION scope
          variable.

          --
          Azadi Saryev
          Sabai-dee.com
          Vientiane, Laos
          http://www.sabai-dee.com
          • 2. dynamic session variable names
            insuractive Level 3
            You may not be that familiar with coldfusion scope structures. Azadi's point is that Variables["somevar"] only sets variables in the local or Variables scope. If you want to use the scope structure notation with session variables, you need to use the following syntax: Session["someVar"]

            Try:

            <cfset Session["#res.system#_Status"] = "Unknown" />