This works: ($this->Task->save('active', '0')
This does not: ($this->Task->save('active', '1')
it fails model validation: Model->Task
'active' => array(
'boolean' => array(
'rule' => array('boolean'),
),
),
TaskController.php
This works:
public function deactivate ($id = null) {
$this->Task->id = $id;
if (!$this->Task->exists()) {
throw new NotFoundException(__('Invalid task'));
}
$this->request->onlyAllow('post');
if ($this->Task->save('active', '0')) {
$this->Session->setFlash(__('The task has been saved'));
$this->redirect($this->referer());
} else {
$this->Session->setFlash(__('The task could not be saved. Please, try again.'));
}
This does not:
public function activate ($id = null) {
$this->Task->id = $id;
if (!$this->Task->exists()) {
throw new NotFoundException(__('Invalid task'));
}
$this->request->onlyAllow('post');
if ($this->Task->save('active', 1)) {
$this->Session->setFlash(__('The task has been saved'));
$this->redirect($this->referer());
} else {
$this->Session->setFlash(__('The task could not be saved. Please, try again.'));
$this->redirect($this->referer());
}
}
Here is the call from View/Tasks/index.ctp:
<?php
if ($task['Task']['active'] == 1){
echo $this->Form->postLink(__('Deactivate'), array('action' => 'deactivate', $task['Task']['id']),null, __('Are you sure you want to return # %s to the project?', $task['Task']['id']));
} else {
echo $this->Form->postLink(__('Activate'), array('action' => 'activate', $task['Task']['id']),null, __('Are you sure you want to send # %s to your todo list?', $task['Task']['id']));
}
?>
mysql db: field 'active' is type "tinyint".
Also, the checkbox form control generated by Bake in Views/Tasks/edit.ctp works just fine.
I have also tried the following:
($this->Task->save('active', 1)
($this->Task->save('active', true)
($this->Task->save('active', 'true')
($this->Task->save('active', '2')
This:
($this->Task->save('active', `1`) //notice the tic marks
seems to bypass validation, but does not update the database.