Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用CakePHP读取对象属性_Php_Cakephp_Cakephp Model - Fatal编程技术网

用CakePHP读取对象属性

用CakePHP读取对象属性,php,cakephp,cakephp-model,Php,Cakephp,Cakephp Model,我第一次使用CakePHP,在我的控制器中,我需要切换模型实例属性的状态: function toggleAutoMark($id = null) { $this->Test->id = $id; $this->Test->saveField('automark', !$this->Test->read('automark')); $this->redirect(array('controller' => 'tests',

我第一次使用CakePHP,在我的控制器中,我需要切换模型实例属性的状态:

function toggleAutoMark($id = null) {
    $this->Test->id = $id;
    $this->Test->saveField('automark', !$this->Test->read('automark'));
    $this->redirect(array('controller' => 'tests', 'action' => 'view', $id));
}
我不知道我是否应该使用read()方法,但这将返回一个数组(这不是我认为文档中所说的)


不起作用,可能是因为实例尚未加载。

您可能正在查找

Model::field()
因此

$this->Test->field('automark');
虽然从性能角度来看,这不是一个很好的主意

updateAll执行一个原子查询,这在这里更适合您(请参阅相关文档)

$this->Test->field('automark');