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

    I’m getting an object with
    $object = $modx->getObject($classname, $myid]);
    

    Now I want to save/insert it into another table (with the same structure of course). How can I do this?
    Is there a way to change the classname or simply create a new object like
    $newobject = $modx->newObject($newclassname, $object); 
    

    without copying every field?

    Sorry for the stupid question, but I really couldn’t find a way.
      • 21257 MODX Staff
      • 730 Posts
      Try:
      $newobject = $modx->newObject($newclassname, $object->toArray());
      $newobject->save();
      

        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 9710
        • 24 Posts
        Yeah, it’s working.

        thank you!