Modal edit cakephp

Asked

Viewed 231 times

3

I’m doing a CRUD all on my INDEX but I’m having trouble in the bootstrap modal parts. I made an EDIT button where it receives id but when I click it always brings the modal vázio.

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

1 answer

1


Place the codes inside the Try/catch block, 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());

    }

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.