<?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);
Array ( [0] => http://test.example.eu/ [1] => http://test.example.com/ [2] => http://test.example.co.uk/)
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
$context->set('site_url','http://blabla.example.de');
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.
<?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');http://test.example.com/
http://test.example.com/
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 :\.
Quote from: Gibbs at Nov 20, 2012, 03:30 AMStrange. 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.
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?
I mean you could set site_url permanently depending on a condition (and use the other two settings to determine what is what).