We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21792
    • 37 Posts
    I’ve been pulling my hair our for 3 days trying to figure out why my extra contexts were returning 404. http://modxcms.com/forums/index.php/topic,60223.0.html" target="_blank" rel="nofollow">I finally figured it out, but it got me thinking.

    I think it would be a good idea if contexts could have aliases, so that different contextKeys initialise the same context.

    For example, instead of

    $modx->initialize('web');


    I have

    if(strpos($_SERVER['SERVER_NAME'],'example1.com')> -1) {
            $modx->initialize('web');
    } else {
    
            $key = str_replace('www.','',$_SERVER['SERVER_NAME']);
    
            if(strpos($_SERVER['SERVER_NAME'],'example2.mysite.com') > -1) {
                    $key = "example2.com";
            }
    
            if(strpos($_SERVER['SERVER_NAME'],'example3.mysite.com') > -1 ){
                    $key = "example3.com";
            }
    
            $modx->initialize($key);
    }


    If I could just have

    $modx->initialize($_SERVER['SERVER_NAME']);


    then modx could/would look for context settings that match the supplied key and initialize that context. I suggest that it looks for a context setting of ’context_alias’ and delimits on comma, pipe, or similar

    That way a developer could use subdomains, $_GET variables, etc etc to quickly move between contexts on just one modx installation
    • Perhaps a silly suggestion... name your contexts to your domain?

      Strip off the www. if it’s there and then pass it through?
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 21792
        • 37 Posts
        Quote from: Mark at Feb 02, 2011, 07:45 PM

        Perhaps a silly suggestion... name your contexts to your domain?

        Strip off the www. if it’s there and then pass it through?

        That’s exactly what gave rise to the suggestion - but I needed a way of having multiple domains point at each context (5 contexts, 3 domains, 4 test domains).

        I’ve hacked the index file to achieve this, but if context aliases were available then I wouldn’t have to