Modal edit cakephp

2

I'm doing a CRUD all in my INDEX but I'm having trouble with the bootstrap modal parts. I made an EDIT button where it gets id but when I click it it always follows the modal empty.

<a data-toggle="modal" data-target="#myModal2" class="btn btn-default"  role="button" href="editar/<?=$cliente['Cliente']['id'];?>">Alterar</a>

My controller:

public function editar($id = null) { 
    if (!$id) {
        throw new NotFoundException(__('<div class="pull-right"><div class="alert alert-success"><strong>Erro entre em contato com o suporte.</strong></div></div>'));
    }
    $cliente = $this->Cliente->findById($id);
    if (!$cliente) {
        throw new NotFoundException(__('<div class="pull-right"><div class="alert alert-success"><strong>Erro entre em contato com o suporte.</strong></div></div>'));
    }

    if ($this->request->is('post') || $this->request->is('put')) {

        $this->Cliente->id = $id;

        if ($this->Cliente->save($this->request->data)) {

            $this->Session->setFlash(__('<div class="pull-right"><div class="alert alert-success"><strong>Cliente atualizado com sucesso.</strong></div></div>'));
            $this->redirect(array('action' => 'index'));
        } 
    }
    if (!$this->request->data) {
        $this->request->data = $cliente;
    }
    $this->autoRender = false;
}
    
asked by anonymous 09.05.2015 / 15:45

1 answer

1

Put the codes inside the try / catch blocks, to see which error is thrown by Exception

public function editar($id = null) { 

    try {

        //code

    } catch (PDOException $e) {

        exit('Error: '. $e->getMessage());

    } catch (NotFoundException $e) {

        $this->set('error_alert', $e->getMessage());

    }

}
    
09.05.2015 / 18:15