We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17959 ☆ A M B ☆
    • 57 Posts
    Magnatron [Maarten Wolzak] Reply #1, 13 years ago
    I'm working on a solution for using a staging area and a production server. To be able to do user administration on the MODx on the staging area, I want to connect to a different server within a CMP.
    I know I can create an extra instance of MODx by using:

    $m2 = new modx();
    $m2->initialize('mgr');

    But how do I go about connecting that instance to the database on the production server?
      • 17959 ☆ A M B ☆
      • 57 Posts
      Magnatron [Maarten Wolzak] Reply #2, 13 years ago
      Found my own answer at http://rtfm.modx.com/xpdo/2.x/getting-started/using-your-xpdo-model/database-connections-and-xpdo#DatabaseConnectionsandxPDO-DefiningMultipleConnections%28xPDO2.2%29

      Instead of instantiating a new modx, instantiate a new xPDO:
      $dsn = "mysql:host=$host;dbname=$dbname;port=$port;charset=$charset";
      $xpdo = new xPDO($dsn, $username, $password);

      And off I go.
        • 17959 ☆ A M B ☆
        • 57 Posts
        Magnatron [Maarten Wolzak] Reply #3, 13 years ago
        Nope. I cheered too soon. Not working. The new xPDO does not have the MODx data mapping.

        So i ran through the API docs and found you can add a configPath when creating a new MODx instance.
        Now it works:

        $mam = MODX_API_MODE;
        define('MODX_API_MODE', true);
        $m2 = new modx(MODX_CORE_PATH."components/mycomponent/"); // Don't include the 'config.inc.php' filename itself.
        $m2->initialize('mgr');
        if($mam!=MODX_API_MODE) define('MODX_API_MODE', $mam);

        (Added the API MODE to stop the new MODx from handling the request.)
          • 17959 ☆ A M B ☆
          • 57 Posts
          Magnatron [Maarten Wolzak] Reply #4, 13 years ago
          Nope. I cheered too soon. Not working. The new xPDO does not have the MODx data mapping.

          So i ran through the API docs and found you can add a configPath when creating a new MODx instance.
          Now it works:

          $mam = MODX_API_MODE;
          define('MODX_API_MODE', true);
          $m2 = new modx(MODX_CORE_PATH."components/mycomponent/"); // Don't include the 'config.inc.php' filename itself.
          $m2->initialize('mgr');
          if($mam!=MODX_API_MODE) define('MODX_API_MODE', $mam);

          (Added the API MODE to stop the new MODx from handling the request.)