I can not update a field in CakePHP with $ this-Model-saveField ()

1

I can not update a particular field in CakePHP.

When you run $this->OrdemServico->saveField() , it simply does not execute.

Code:

class OrdemServico extends AppModel {

    public $name = "OrdemServico";
    public $useTable = "ordens_servico";
    public $belongsTo = array(
        "Cliente" => array(
            "className" => "Cliente",
            "foreignKey" => "id_cliente"
        ),
        "Responsavel" => array(
            "className" => "Usuario",
            "foreignKey" => "responsavel"
        ),
        "Equipamento" => array(
           "className" => "Equipamento",
           "foreignKey" => "equipamento"
        ),
        "ModoEntrega" => array(
           "className" => "ModoEntrega",
           "foreignKey" => "modo_entrega"
        )
    );

}


class OrdemServicoController extends AppController {
     public function cancelar() {
        try {
            $this->layout = "ajax";
            $this->autoLayout = false;

            $data = $this->request->data;
            $id = $data["question"]["parameter"];
            $destino = unserialize($data["question"]["callback"]);

            $this->OrdemServico->id = $id;
            $this->OrdemServico->saveField("OrdemServico.cancelado", true);

            $this->Dialog->alert("A ordem de serviço foi cancelada com sucesso.");
            $this->redirect($destino);
        } catch (Exception $ex) {
            $mensagem = "Ocorreu um erro no sistema ao atualizar a ordem de serviço.";

            $this->Dialog->error($mensagem, $ex->getMessage());
            $this->redirect(array("action" => "index"));
       }
    }
}

Question.ctp

<div id="dialog-question" class="modal-dialog">
    <?php
    echo $this->Form->create(null, array(
        "url" => array(
            "controller" => "ordem_servico",
            "action" => "cancelar"),
        "id" => $form_name,
        "role" => "form"
    ));

    echo $this->Form->hidden("question.parameter");
    echo $this->Form->hidden("question.callback", array("value" => serialize($retorno)));
    ?>

    <div class="modal-content">
        <div class="modal-header" style="cursor: move">
            <button id="btn-question-close" type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title"><i class="fa fa-bell"></i>&nbsp;&nbsp;Sistema de Ordem de Serviço</h4>
        </div>
        <div class="modal-body">
            <p><?= h($message) ?></p>
        </div>
        <div class="modal-footer">
            <button id="btn-cancel-modal" type="button" class="btn btn-danger"><?= $buttons["cancel"] ?></button>
            <button id="btn-default-modal" type="submit" class="btn btn-success"><?= $buttons["ok"] ?></button>
        </div>
    </div>
    <?= $this->Form->end() ?>

I would like to know what's going on, because the system can not update the field at all.

    
asked by anonymous 03.08.2015 / 21:56

1 answer

0

You are passing the ID (int) of the field line you want to update?, $data["question"]["parameter"] ; is the primary key of the model?

Example

function some($id = null){
       //...
       $this->Model->id = $id;
       $this->Model->saveField("Model.campo", true);
       //....
}

action.ctp

echo $this->Form->create();
echo $this->Form->input('Model.id', array('type' => 'hidden'));
echo $this->Form->end('Enviar');
    
10.09.2015 / 22:37