I made a panel with some functions of the tree, edit, move and delete. Until then my delete is working when I want to delete a specific thing without children. The problem is that when I delete an item that has children, it deletes all the children together, and my intention was for it to change the parent_id of the children of the item that will be deleted, to the item that I selected in the list. p>
PS: this $this->request->data['Navigation']['childs']
is the id that I have a menu with a list returning all the ids I have available so that the person can change them.
public function apagar($id){
if ($this->request->is('post')){
empty($this->request->data['Navigation']['childs']) ? null : $this->request->data['Navigation']['childs'];
$this->Navigation->updateAll(array(
'Navigation.parent_id' => $id,
), array(
'Navigation.parent_id' => $this->request->data['Navigation']['childs'],
));
$this->Navigation->id = $id;
$this->Navigation->delete();
$this->Session->setFlash('Menu Apagado!');
return $this->redirect('/navegacao');
} else {
$tree = $this->Navigation->generateTreeList(null, null, null, ' - ');
unset($tree[$id]);
$this->set('tree', $tree);
}
}