3 Replies Latest reply on Apr 23, 2008 9:08 PM by BKBK

    Sharing Application Variables

    pflynn02
      I have an Application.cfm in the root of my site called App1. I have a directory in this site called Signup with an Application.cfm named App2, I would like App2 to check my Session.LoggedIn variable of the App1 application. Is this possible to do? If so how, i have been racking my brain on this for a few days. Thanks in advance!
        • 1. Re: Sharing Application Variables
          Level 7
          pflynn02 wrote:
          > I have an Application.cfm in the root of my site called App1. I have a
          > directory in this site called Signup with an Application.cfm named App2, I
          > would like App2 to check my Session.LoggedIn variable of the App1 application.
          > Is this possible to do? If so how, i have been racking my brain on this for a
          > few days. Thanks in advance!
          >

          A template has access to the application scope defined by the name given
          in the <cfapplication name="..."> tag or the this.name of a an
          Application.cfc

          A template can declare <cfapplicaiton ...> more then one time. So you
          can do something like this in a specific template to combine the two
          application scopes.

          <cfapplication name="App1"...>

          <cfset variables.localVariable1 = application.applicationOneVar>

          ...

          <cfapplication name="App2"...>

          <cfset variables.localVariable2 = application.applicationTwoVar>


          <cfif variables.localVariable1 = variables.localVariable2>
          <!--- Do stuff with the comparison --->
          </cfif>
          • 2. Re: Sharing Application Variables
            pflynn02 Level 1
            Here is exactly what im trying to do, im not sure I understand your example...

            App1 has a variable called : SESSION.MYACCOUNT

            App2 needs to see if that SESSION.MYACCOUNT variable IsDefined BUT
            when I tried to check it, it is looking in the App2 sessions not App1, how do I look in App1 for the SESSION.MYACCOUNT? Thanks...
            • 3. Re: Sharing Application Variables
              BKBK Adobe Community Professional & MVP
              App2 needs to see if that SESSION.MYACCOUNT variable IsDefined BUT when I tried to check it, it is looking in the App2 sessions not App1, how do I look in App1 for the SESSION.MYACCOUNT?

              You can't. Sessions are privately owned by applications. App2 cannot read App1's session variables.

              The following strategy will work. Assume the location of App1's Application.cfc file is wwwroot/app1/. Then add the 'extends' attribute to App2's Application.cfc file, as follows

              <cfcomponent extends="app1.Application" ... etc>

              App2 can now have access to App1's session variables. However, this is not a sweet structure, as it defeats the purpose of separate applications.