Change id children to another id

0

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);
        }
    }
    
asked by anonymous 31.03.2015 / 21:02

1 answer

0

Note that this line below does not result in anything.

empty($this->request->data['Navigation']['childs']) ? null : $this->request->data['Navigation']['childs'];

To be honest, I did not quite understand what this logic is like to delete the record or not. But it looks like your intention was to use the value of your childs column to do this update. So you have to do something like this:

if (!empty($this->request->data['Navigation']['childs'])) {
    // Possui filhos
    $this->Navigation->updateAll(
                array('Navigation.parent_id' => $id),
                array('Navigation.parent_id' => $this->request->data['Navigation']['childs'])
    );
} else {
    // Não possui filhos
}
    
31.03.2015 / 21:16