// Part 1 $pagetitle = "my ressource"; $parent = "0"; $alias = "myalias"; $doc = $modx->newObject('modDocument'); $doc->set('parent',$parent); $doc->set('pagetitle',$pagetitle); $doc->set('alias',$alias); $doc->save(); // Part $newdoc = $modx->getObject('modDocument', array('pagetitle'=>$pagetitle)); $id = $newdoc->get('id');
This question has been answered by Bruno17. See the first response.
$doc->save(); $id = $doc->get('id');
// Part 1 $pagetitle = "my ressource"; $parent = "0"; $alias = "myalias"; $doc = $modx->newObject('modDocument'); $doc->set('parent',$parent); $doc->set('pagetitle',$pagetitle); $doc->set('alias',$alias); $doc->save(); // Part $newdoc = $modx->getObject('modDocument', array('pagetitle'=>$pagetitle)); $id = $newdoc->get('id');
We need to overwrite default saveNewObject method to get rid of the unsetting pre-specified ID.
$bind = $this->_prepareDataForSave($object);
if ($this->_isPkAutoIncrement) {
unset($bind[$this->getIdFieldName()]);
}
$this->getConnection()->insert($this->getMainTable(), $bind);