We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34466
    • 19 Posts
    Hi. I get weekly product updates to a mysql database. Is there any way to import the data directly into the modx database or to create pages directly by modx from a seperate database? Thanks.
      • 3749
      • 24,544 Posts
      Creating resources in code in MODX Revoution is fairly simple. I just happened to have the code in my clipboard.

      $title = 'MyPage';
      $pageAlias = 'my-page';
      $templateId = 2;
       
      $fields = array(
        'pagetitle' => $title,
        'template' => $templateId,
        'alias' => $pageAlias,
        /* other fields here as necessary. System defaults will be used if empty */
      };
       
      /* create and save new resource */
      $response = $this->modx->runProcessor('resource/create', $fields);
       
       
      /* optional error handling */
       
      if ($response->isError()) {
          if ($response->hasFieldErrors()) {
              $fieldErrors = $response->getAllErrors();
              $errorMessage = implode("\n", $fieldErrors);
          } else {
              $errorMessage = 'An error occurred: ' . $response->getMessage();
          }
          
          return $errorMessage;
       
      } else {
          /* optional - in case you want the ID of the new resource (e.g., for makeUrl() ) */
          $object = $response->getObject();
       
          $resourceId = $object['id'];
            
      }


      You could have to add code at the top to get the data from the other database (or export it to a CSV file and read that file).

      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODx info for everyone: http://bobsguides.com/MODx.html
        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
        • 34466
        • 19 Posts
        Wow thats soo cool! Thanks so much Bob!