You can’t really use the $modx object outside the scope of the current request being handled by it. Changes to the architecture will allow this in the future, but for now, it’s not practical. I’m not saying it’s impossible, but certainly not designed for practical usage outside of handling and parsing a request itself.
<?php $id = $_REQUEST['id']; $sideId = $_REQUEST['sideId']; if (!isset($id) || empty($id)) { echo 'Keine Auswahl getroffen'; return; } $path = "../../"; include_once $path . "manager/includes/config.inc.php"; include_once $path . 'manager/includes/document.parser.class.inc.php'; include_once $path . "manager/processors/cache_sync.class.processor.php"; $modx = new DocumentParser(); $table = $modx->getFullTableName('site_content'); $temptable = $modx->getFullTableName('site_templates'); $sql = 'update modx_site_content set template=' . $id; $modx->db->query($sql); $sync = new synccache(); $sync->setCachepath($path . "assets/cache/"); $sync->setReport(false); @$sync->emptyCache(); if (isset($sideId)) { $modx->sendRedirect($path . "index.php?id=" . $sideId); return; } $displayName = $modx->db->getValue("select templatename from $temptable where id=$id"); echo "Template <b>$displayName</b> changed.<br>" . "<p>Please use the back button" . "<p><b> and load the site again (key F5).</b>";