I’m using CakePHP for the first time and inside my controller I need to toggle the state of a property of an instance of my model:
function toggleAutoMark($id = null) {
$this->Test->id = $id;
$this->Test->saveField('automark', !$this->Test->read('automark'));
$this->redirect(array('controller' => 'tests', 'action' => 'view', $id));
}
I’ve no idea if I’m meant to be using a read() method, but this returns an array (which is not what I thought the docs said).
$this->Test->automark
doesn’t work, presumably because the instance hasn’t been loaded.
you are probably looking for
and therefore
although this is not a very good idea from a performance perspective.
Model::updateAll performs an atomic query which would suit you better here (see the documentation on that).