Set the Path for newly created DataObjects

Hello, I am trying to set the path for newly created objects by using the setPath function.
The code looks as follows:

$obj = new DataObject\MyCategory;
$obj->setId(‘1234’);
$obj->setKey(‘MyCategory’);
$obj->setPath(’/MyCategory/Subfolder/’);
$obj->save();

however after the save() function is called, the path is not saved.
After setPath is called the o_path is set correctly, but after the save function it is again set to /.

Am I doing something wrong?

I don’t think you can set the Path directly. The path gets generated via the parent object:

$obj->setParent(DataObject\Folder::getByPath("/MyCategory/Subfolder"));
1 Like

Thank you, it is working now!