We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33372
    • 1,611 Posts
    Quote from: mattcdavis1 at Sep 18, 2009, 09:09 PM

    Dude - you rock! That is so freakin’ cool. It’s working great. Thanks!
    Don’t thank me. Thank Linux. Linux rox!
      "Things are not what they appear to be; nor are they otherwise." - Buddha

      "Well, gee, Buddha - that wasn't very helpful..." - ZAP

      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: mattcdavis1 at Sep 18, 2009, 05:03 PM

      The docs are not accurate then; you can set up contexts and switch to different ones using a plugin OnWebPagePrerender or by modifying your index.php. I’ve described this in the forums, but I’ll have to search for the thread. Please bump the thread if you don’t mind and keep the conversation public.
      Matt:

      Here is what I was talking about, and it’s OnHandleRequest event, not OnWebPagePrerender...

      Also, re: assets folder, there are already ways to do this without creating symbolic links. There are constants defined in your config file that always point to the "main" directories, i.e. MODX_ASSETS_URL and MODX_ASSETS_PATH, while your Context Settings can override this value in your config for each Context, i.e. $modx->getOption(’assets_url’) and $modx->getOption(’assets_path’). Using these conventions when building Extras that work in multi-context configurations will be critical. I often use these like: $modx->getOption(’assets_path’, $scriptProperties, MODX_ASSETS_PATH), which allows me to get the assets_path from the Snippet/Plugin properties if specified, falling back to Context settings and finally to the constant from the configuration.
        • 18654
        • 191 Posts
        Quote from: OpenGeek at Sep 19, 2009, 11:26 AM


        Matt:

        Here is what I was talking about, and it’s OnHandleRequest event, not OnWebPagePrerender...


        It seems like the plugin approach is the way to go since I could avoid having to setup extra folders in my directory. However, I’m having problems with implementation. Here’s a link to 1 1/2 minute screencast documenting my attempt http://screenr.com/fl7. I’m sure it’s a simple error but I can’t figure out what it is. Right now, both the main domain and subdomain are pointing to the Main ModX directory. Also, I forgot to show in the screencast but I do have "OnHandleRequest" enabled under System Events.
          God does not save those who are only imaginary sinners. Be a sinner, and let your sins be strong, but let your trust in Christ be stronger, and rejoice in Christ who is the victor over sin, death, and the world.
          • 22303 MODX Staff
          • 10,725 Posts
          Everything in the screencast I could actually see looks right, but make sure the site_start you have specified is published. I’m working on a site using the plugin right now and it is working flawlessly for me, so not sure what the issue could be. Also, make sure you manually clear the cache after changing the context settings and saving/registering the plugin...
            • 18654
            • 191 Posts
            I just did a quick check to make sure the OnHandleRequest Event was working by putting
            header("Location: http://www.google.com");
            as the first line of code for the plugin. It worked successfully, so that can be eliminated as the problem.

            Next, I placed that same line of code underneath the "case" options like this:

            <?php
            
            switch ($modx->getOption('http_host')) {
               case 'dev.3eimpact.com:80':
               case 'dev.3eimpact.com':
                  // if the http_host is of a specific domain, switch the context
                  //$modx->switchContext('dev');
            header("Location: http://www.google.com");  
                  break;
               default:
                  // by default, don't do anything
                  break;
            }
            ?>
            


            Here I got nothing. So the "case" values are not producing a match to http_host. Is there some way I could get the value of "http_host" to echo on screen so I could see what value it holds?

            Update: I changed the case value to: ’3eimpact.org’ and it triggered. So for some reason
            $modx->getOption('http_host'
            is returning 3eimpact.org instead of dev.3eimpact.com.

            -matt
              God does not save those who are only imaginary sinners. Be a sinner, and let your sins be strong, but let your trust in Christ be stronger, and rejoice in Christ who is the victor over sin, death, and the world.
              • 22303 MODX Staff
              • 10,725 Posts
              Quote from: mattcdavis1 at Sep 19, 2009, 02:12 PM

              Here I got nothing. So the "case" values are not producing a match to http_host. Is there some way I could get the value of "http_host" to echo on screen so I could see what value it holds?
              Well, I prefer to use $modx->log() to send information to the core/cache/logs/error.log file:
              $modx->log(MODX_LOG_LEVEL_ERROR, print_r($modx->config['http_host'], true));

              You can also use MODX_LOG_LEVEL_FATAL instead of ERROR to get it to stop and it should present the error on screen when it die()’s.
                • 18654
                • 191 Posts
                The error log confirmed the update on my previous post. It is seeing dev.3eimpact.com as 3eimpact.org.
                [2009-09-19 15:39:56] (ERROR @ /index.php) 3eimpact.org
                [2009-09-19 15:39:59] (ERROR @ /index.php) 3eimpact.org
                [2009-09-19 15:40:02] (ERROR @ /index.php) 3eimpact.org
                

                  God does not save those who are only imaginary sinners. Be a sinner, and let your sins be strong, but let your trust in Christ be stronger, and rejoice in Christ who is the victor over sin, death, and the world.
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: mattcdavis1 at Sep 19, 2009, 02:42 PM

                  The error log confirmed the update on my previous post. It is seeing dev.3eimpact.com as 3eimpact.org.
                  [2009-09-19 15:39:56] (ERROR @ /index.php) 3eimpact.org
                  [2009-09-19 15:39:59] (ERROR @ /index.php) 3eimpact.org
                  [2009-09-19 15:40:02] (ERROR @ /index.php) 3eimpact.org
                  


                  Then I suppose your web server is not reporting the proper domain in $_SERVER[’HTTP_HOST’].
                    • 18654
                    • 191 Posts
                    OpenGeek - thanks so much for you help. I finally got it working with the following code:
                    <?php
                    switch ($_SERVER['HTTP_HOST']) {
                    
                       case 'dev.3eimpact.com:80':
                       case 'dev.3eimpact.com':
                          // if the http_host is of a specific domain, switch the context
                          $modx->switchContext('dev');  
                          break;
                       default:
                          // by default, don't do anything
                          break;
                    }
                    ?>
                    


                    It seems like for some reason the modx object was returning the wrong value.

                    Thanks again!

                    -matt
                      God does not save those who are only imaginary sinners. Be a sinner, and let your sins be strong, but let your trust in Christ be stronger, and rejoice in Christ who is the victor over sin, death, and the world.