Cakephp 2.x How to use updateAll with tinyint data type

Hi,
I’m trying to update a tinyint data field in my database.

The following code is the view:

<?php echo $this->Session->flash(); ?>
 <?php echo $this->Form->create("myForm", array('type' => 'file', 'action' => "updateData"));?>
 <?php echo $this->Form->input('myForm.myDescription', array("class" => "form-control", 'label' => false, "placeholder" => __d('myView', "description"), 'autocomplete' => 'off', 'required' => false, 'error' => false)); ?>
 <?php echo $this->Form->input('myForm.mySingleCheckbox', array('label' => false, 'type' => 'checkbox')); ?>
 <?php echo $this->Form->submit(__d('myView', "SAVE"), array("div" => false, "class" => "btn btn-primary pull-right")); ?>
 <?php echo $this->Form->end(); ?>

And the controller is the following:

public function updateData(){
    $user_id = $this->Auth->user("id");
        if (!isset($user_id)) { $this->redirect('/'); }

        if (!empty($this->request->data)) { 
      $this->loadModel("myModel");
      $db = ConnectionManager::getDataSource("default");
      $response = $this->myModel->updateAll(
        array(
          'myModel.myDescription'   => $db->value($this->request->data["myModel"]["myDescription"], 'string'),
          'myModel.mySingleCheckbox'    => $db->value($this->request->data["myModel"]["mySingleCheckbox"], 'boolean'), 
        ),
        array('myModel.id' => $this->request->data["myModel"]["id"])
      ); 
      
      if ($response) {
        $this->Session->setFlash(__d('myForm', "OK"), 'form_success');                    
      } else {  // errore SAVE
        $this->Session->setFlash(__d('myForm', "KO"), 'form_error');
      }
        }
  }

As result, the field ‘myDescription’ is saved, but ‘mySingleCheckbox’ is not.
I don’t know how to solve this issue.

Thanks in advance

1 Like