twitter-bootstrap – Modal editar cakephp

Question:

I'm doing a CRUD all in my INDEX but I'm having a problem in the modal parts of the bootstrap. I made an EDIT button where it receives id but when I click it always brings the empty modal.

<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;
}

Answer:

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

public function editar($id = null) { 

    try {

        //code

    } catch (PDOException $e) {

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

    } catch (NotFoundException $e) {

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

    }

}
Scroll to Top