We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37258
    • 34 Posts
    I have a connection to an external DB setup and running perfectly, I am now trying to improve the output so that rather than just returning variables in the snippet I can use a chunk and custom placeholders. I believe this is possible using Bobs 'CreateXpdoClasses' snippet but I have to admit I'm confused by the following line which puports to advise me on how connecting to the external DB is accomplished:

    To do this, you would need to set the following variables after including the config file, but before creating the $modx object

    I've used the snippet successfully before on Custom tables in the modx DB but honestly, that advice above means nothing to me. What config file? What $modx object?! I've tried adding DBC details further down in the CreateXPDOClasses snippet but to no avail, and I'm not sure where I'm going wrong!

    Be lovely if someone could offer me some advice to get me started!
      • 3749
      • 24,544 Posts
      I don't suppose it's an option to move the data into the MODX DB? That would be the simplest solution and would give you faster results and less strain on the server.

      The script is including the core/config/config.inc.php file, which sets the access variables for the MODX DB. The line above is saying that you'd need to change the values of those variables before the new $modx line in order to connect to your other DB. TBH, I don't think it's practical to use xPDO with two different databases on the same site. I could be wrong.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 32699 ☆ A M B ☆
        • 427 Posts
        I have to agree Bob. Using two persistent xPDO connections is over the top.

        Just put them in the modx database BUT use a prefix to differentiate them (and try not using modx-something either like MiniShop2 does).

        I typically use initials ut_ for UserTracker, cb_ for CodedBonus, etc.

        This way all of your tables will be together but stand apart from the primary modx tables.

        Here is a cheat snippet to quickly import your project into modx:

        initializeModel
        <?php
        /**
         * File initializeModel.php (requires MODx Revolution 2.1)
         * Created on: 8/3/11 at 8:24 AM
         * Project shawn_wilkerson
         * @package all
         * @version 1.0
         * @category 
         * @author W. Shawn Wilkerson
         * @link http://www.shawnWilkerson.com
         * @copyright Copyright (c) 2011, W. Shawn Wilkerson. All rights reserved.
         * @license 
         *
         */
         
        $packageName = strtolower($package);
        $modelPath = $modx->getOption($packageName . '.core_path', null, $modx->getOption('core_path') . 'components/' . $packageName . '/') . 'model/';
        $schema = $modelPath . 'schema/' . $packageName . '.mysql.schema.xml';
        $modx->setLogLevel(xPDO::LOG_LEVEL_INFO);
        $modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
        $manager = $modx->getManager();
        $generator = $manager->getGenerator();
        $success = $generator->parseSchema($schema, $modelPath);
        $modx->addPackage($packageName, $modelPath, $prefix);
        $manager = $modx->getManager();
        $tlist = explode(',', $tables);
        foreach ($tlist as $t) {
             $success += $manager->createObjectContainer(trim($t));
        }
        return ($success > count($tlist)) ? '<h2>Success</h2><p>Model Created at ' . $modelPath . $packageName . ' and all tables successfully created.</p>' : '<h2>Operation Failed</h2>';
        


        Snippet Call:
        [[!initializeModel?package=`usertracker`&prefix=`ut_`&tables=`utIpAdress,utLoginLog,utCount`]]
        


        The &tables must match the object description class names in your schemata
        Make sure you are adhereing to /core/components/packagename/model/schema

        All lower case.

        You may have to manually create /core/components/packagename/model/packagename yourself, but I don't think so [ed. note: wshawn last edited this post 13 years, 2 months ago.]
          Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

          Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com