We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21838
    • 284 Posts
    Hi all,

    I’ve got some strange issues with my handling of multiple languages / contexts and the gateway.

    First I’ve tried to solve it with gateway plugin:
    if($modx->context->get('key') != "mgr"){
            //grab the current domain from the http_host option
            switch($modx->getOption('http_host')) {
                case 'en.url.com':
                    //switch the context
                    $modx->switchContext('english');
                    //set the cultureKey
                    $modx->setOption('cultureKey', 'en');
                    break;
                
                default:
                 // Set the default language/context here
                    $modx->switchContext('web');
                    $modx->setOption('cultureKey', 'de');
                    break;
    
            }
        }
        

    This didn’t worked out for me as there seems sth. wrong in the if statement with the get function?
    Of course, OnHandleRequest was enabled.

    Now, when entering the same code in index.php I’ve get this error message:
    Call to a member function get() on a non-object in /index.php on line 91

    Then tried another solution of handling I’ve found:
    /* setup for multiple domains */
    switch(strtolower(MODX_HTTP_HOST)) {
       case 'www.modx-templates.com:80':
       case 'www.modx-templates.com':
          // if the http_host is modx-templates.com, switch the context to web
          $modx->initialize('web');
          break;
       case 'www.ffmwireless.de:80':
       case 'www.ffmwireless.de':
          // if the http_host is ffmwireless.de, switch the context to ffmwireless
          $modx->initialize('ffmwireless');
          break;
       case 'www.thesearchgoeson.com:80':
       case 'www.thesearchgoeson.com':
          // if the http_host is thesearchgoeson.com, switch the context to thesearch
          $modx->initialize('thesearch');
          break;
      default:
          // by default / if no other rule can be applied, load 'web' context
          $modx->initialize('web');
          break;
    }
    


    in gateway plugin this didn’t work, too.
    But when entering in index.php it works fine!

    Can anyone explain me that? And perhaps you know what’s wrong in the if statement as I’m not a developer who’s into the modx code wink

    Best and thanks,
    Anselm


    UPDATE:

    solved the problem. Had had http_host settings in my context settings. After removing them gateway handler did his work again.
      MODX Free Template Base: MODX-Boilerplate | my blog (lots of MODX stuff) | my gitHub (translations) | MODX User Groups Germany (Facebook)