We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23054
    • 62 Posts
    I have a form that calls my own php file.
    In that file I need access to the functions of the class DocumentParser.

    The usual way to define $global modx does not work.

    No I have no idea how to get this variable passed as hidden parameter in a form in order to use the functionality of the class.

    Creating a new instance works but in that case I do not get the values for the document pathes as they should be because the script is outside from modx document pathes.

    When I call $modx->makeUrl(docId), where docId is a vaue passed by form, I got back my own script path - but I need the modx-path in order to create an appropriate link.

    I have no idea huh

    • 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.
        • 23054
        • 62 Posts
        Quote from: OpenGeek at Jul 26, 2006, 01:55 PM

        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.

        Actually, I managed on order to switch templates during runtime grin

        Look at the code.
        $id is the id number of template in database, $sideId is the id of the site, that causes that request by an formular and calls the code below and $path is the relational path from my php-files to modx-root.

        <?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>";