We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27733
    • 99 Posts
    Is the above possible? I’d like to capture a $_SESSION value in the prehook and pass it to the posthook (in case it gets unset during login) ...
      ------
      Server: *nix, ModX Evo 1.0.4, Apache 2.x, PHP 5.x, Mysql 5.x.
      • 28215
      • 4,149 Posts
      Set it as a hidden field in the form.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 27733
        • 99 Posts
        Shaun, thanks for the reply. I should have qualified better what that value is: It’s a multidimensional array that I want to pass. Of course, that can’t be passed in a hidden field ... I could convert it to a json string, but if possible I’d rather not do two conversions to pass it through the form itself. Is there a way to "talk to" the Login object directly via the hooks?
          ------
          Server: *nix, ModX Evo 1.0.4, Apache 2.x, PHP 5.x, Mysql 5.x.
          • 28215
          • 4,149 Posts
          No, since each request begins and ends with page load - PHP is not a persistent language.

          However, you could store the values in the cache:

          $cacheKey = $this->modx->resource->getCacheKey().'/myform-'.session_id();
          $modx->cacheManager->set($cacheKey,$myArrayOfData);
          
          ...
          
          $myArrayOfData = $modx->cacheManager->get($cacheKey);


          The cacheKey here stores it based on a combination of the Resource cache path (so it’s clearable by the resource cache clearing) and the unique user PHP session ID, so it maps to the client. You could also use the registry as well. Up to you.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 27733
            • 99 Posts
            Thanks for the lead. I’d like to use this method, but I keep getting an internal server error (caused by the call to cacheManager). Why might this happen?
              ------
              Server: *nix, ModX Evo 1.0.4, Apache 2.x, PHP 5.x, Mysql 5.x.
              • 27733
              • 99 Posts
              Also, I’m experiencing the internal error when attempting to use postHooks (even with the posthook simply returning "TRUE"). Clues? ...

              UPDATE: This appears to have been caused by an installation issue on the dev server. (The previous post still applies ... trying to utilize the cacheManager is a no-go so far.)
                ------
                Server: *nix, ModX Evo 1.0.4, Apache 2.x, PHP 5.x, Mysql 5.x.
                • 28215
                • 4,149 Posts
                Try running this before calling the cacheManager->set method:

                $modx->getCacheManager();
                  shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com