We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41098
    • 10 Posts
    <?php 
    		
    define('MODX_PATH','/srv/www/html/cms/');
    define('MODX_API_MODE', TRUE);
    
    require_once MODX_PATH.'config.core.php';
    require_once MODX_CORE_PATH.'model/modx/modx.class.php';
    $modx = new modX();
    $modx->initialize('mgr');
    
    $getAllContext = $modx->getCollection('modContext');
          
    foreach ($getAllContext as $context) {			
       $context->prepare();
       $context->setOption('site_url','http://blabla.example.de');									
       $output[]= $context->getOption('site_url');
    }
    		
    print_r($output);
    
    


    It outputs:

    Array ( [0] => http://test.example.eu/ [1] => http://test.example.com/ [2] => http://test.example.co.uk/)

    What i need is to set subdomain to "blabla" so that i can use $modx->makeUrl later with the new subdomain.

    Btw. i can set any custom option with setOption and get it with getOption without any problems. Its just the override of site_url that is not working.

    Any help?
      • 34926
      • 87 Posts
      Is 'blabla' running in its own 'context'? If so just create a new context setting named 'site_url' like you've done with the previous subdomains.

        • 41098
        • 10 Posts
        Quote from: Gibbs at Nov 19, 2012, 05:39 AM
        Is 'blabla' running in its own 'context'? If so just create a new context setting named 'site_url' like you've done with the previous subdomains.


        No - i need to override the default context settings because i want to implement some sort of "staging" so that when i am on dev server it points to http://test.example.com and when i am on development it points to http://blabla.example.com

          • 34926
          • 87 Posts
          Quote from: acidrat at Nov 19, 2012, 05:52 AM

          No - i need to override the default context settings because i want to implement some sort of "staging" so that when i am on dev server it points to http://test.example.com and when i am on development it points to http://blabla.example.com


          What happens if you use:
          $context->set('site_url','http://blabla.example.de');

          Your way should work at a glance.
            • 41098
            • 10 Posts
            Quote from: Gibbs at Nov 19, 2012, 09:13 AM
            Quote from: acidrat at Nov 19, 2012, 05:52 AM

            No - i need to override the default context settings because i want to implement some sort of "staging" so that when i am on dev server it points to http://test.example.com and when i am on development it points to http://blabla.example.com


            What happens if you use:
            $context->set('site_url','http://blabla.example.de');

            Your way should work at a glance.

            Nope doesnt work either, you can try it by yourself. Run this example code:

            <?php 
            		
            define('MODX_PATH','/srv/www/html/trustedshops/cms/');
            define('MODX_API_MODE', TRUE);
            
            require_once MODX_PATH.'config.core.php';
            require_once MODX_CORE_PATH.'model/modx/modx.class.php';
            $modx = new modX();
            $modx->initialize('mgr');
            	
            $contextObject = $modx -> getObject('modContext', 'web');
            $contextObject -> prepare();
            		
            echo $contextObject -> getOption('site_url');
            
            $contextObject -> setOption('site_url','http://blabla.example.de');		
            
            echo $contextObject -> getOption('site_url');


            Output is always the same even if i use $contextObject -> set

            http://test.example.com/
            http://test.example.com/
              • 34926
              • 87 Posts
              Strange. I guess you could approach it differently and have two extra context settings such as site_url_staging and site_url_production. Then you could set site_url (permanently) with set and save. Just a thought until someone can explain why setOption isn't working :\.
                • 41098
                • 10 Posts
                Quote from: Gibbs at Nov 20, 2012, 03:30 AM
                Strange. I guess you could approach it differently and have two extra context settings such as site_url_staging and site_url_production. Then you could set site_url (permanently) with set and save. Just a thought until someone can explain why setOption isn't working :\.

                The main problem is, that i want to use $modx->makeUrl() http://rtfm.modx.com/display/revolution20/modX.makeUrl and it uses the site_url and cannot be forced to use other options like site_url_staging or such.



                  • 33968
                  • 863 Posts
                  Where are you using makeUrl(), is it in the same script you have shown above?

                  Could you use it to make a relative url only, and then just bolt it on to your new site_url?
                    • 34926
                    • 87 Posts
                    Quote from: acidrat at Nov 20, 2012, 03:42 AM
                    Quote from: Gibbs at Nov 20, 2012, 03:30 AM
                    Strange. I guess you could approach it differently and have two extra context settings such as site_url_staging and site_url_production. Then you could set site_url (permanently) with set and save. Just a thought until someone can explain why setOption isn't working :\.

                    The main problem is, that i want to use $modx->makeUrl() http://rtfm.modx.com/display/revolution20/modX.makeUrl and it uses the site_url and cannot be forced to use other options like site_url_staging or such.




                    I mean you could set site_url permanently depending on a condition (and use the other two settings to determine what is what).
                      • 41098
                      • 10 Posts
                      Quote from: okyanet at Nov 20, 2012, 07:20 AM
                      Where are you using makeUrl(), is it in the same script you have shown above?

                      Could you use it to make a relative url only, and then just bolt it on to your new site_url?

                      Yes, same script. I can really use the relative url only but then i need to redesign some code. But if there is no other options i might do that. Thank you for your suggestion.



                      Quote from: Gibbs at Nov 21, 2012, 06:34 AM

                      I mean you could set site_url permanently depending on a condition (and use the other two settings to determine what is what).

                      The problem with this approach is, that when i dump my development db into the prod db i need to manually change each context settings.