We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23637
    • 43 Posts
    Hello,

    I need to add a new resource to another resource (folder)
        $parentFolder = $modx->getObject('modResource', 100);
    
        $newFolder = $modx->newObject('modResource');
        $newFolder->set('pagetitle', $year);
        $newFolder->set('alias', "year-".$year);
        $newFolder->set('isfolder', 1);
        $newFolder->set('Parent', $parentFolder);
    
        $newFolder->save();
    


    Resource has been added to the root folder, but not to resource with id = 100. [ed. note: podeig last edited this post 14 years, 1 month ago.]
      • 4172
      • 5,888 Posts
      try this:

      $parentFolder = 100;
      $newFolder->set('parent', $parentFolder);


      the field is 'parent' not 'Parent' and you need to set it as an integer-value, not as an xpdo-object.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 23637
        • 43 Posts
        Thank you! Works perfect! smiley