We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8425
    • 159 Posts
    Hi,
    I've created a document programmatically. Now I'd like to add it to a resource group this resource belongs to.
    How can I do that? Would the code below work?
    Thanks for your help.

    $fields = array(
      'pagetitle' => $title,
      'template' => $templateId,
      'alias' => $pageAlias,
      'published' => $published,
      'parent' => $parent,
      'hidemenu' => 1,
    };
     
    /* create and save new resource */
    $response = $this->modx->runProcessor('resource/create', $fields);
    $object = $response->getObject(); 
        $resourceId = $object['id']; 
    
        // Set the newly created document to the proper group
        $groupName = 'MyGroup';
        $object->joinGroup($groupName);  
    
      • 3749
      • 24,544 Posts
      It should, though you don't need the object ID and you might have to add this to the end:

      $object->save();
        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