Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.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
Php $this->;协议->;save()-只创建一条记录,为什么?_Php_Mysql_Cakephp_Cakephp 2.5 - Fatal编程技术网

Php $this->;协议->;save()-只创建一条记录,为什么?

Php $this->;协议->;save()-只创建一条记录,为什么?,php,mysql,cakephp,cakephp-2.5,Php,Mysql,Cakephp,Cakephp 2.5,我需要读取表协议中的所有记录,更改已存档的付款,更新所有记录,保存到表中。所以,我的问题是,save()只创建空记录。不更新现有记录。我将向您展示如何: 从表中读取: $agreements = $this->Agreement->find('all'); $payments = $this->Payment->find('all'); 字段操作(部分)(示例): echo调试($agreements)显示正确的阵列,我也尝试过: $this->Agreement

我需要读取表协议中的所有记录,更改已存档的付款,更新所有记录,保存到表中。所以,我的问题是,save()只创建空记录。不更新现有记录。我将向您展示如何:

从表中读取:

$agreements = $this->Agreement->find('all');
$payments = $this->Payment->find('all');
字段操作(部分)(示例):

echo调试($agreements)显示正确的阵列,我也尝试过:

$this->Agreement->save($agreements);

你能帮我解释一下如何写所有的记录吗


Cake 2.5.2 PHP:5.4.4-14

Model::save()
只保存一条记录。如果要保存多条记录,需要使用
Model::saveAll()
Model::saveMany()

对我来说,这看起来不错。我会再检查一遍的。我会检查的。我需要设置recursive=-1吗?我一直在考虑。我可以看到一条记录被写入数据库。但是所有的文件都是空的?你能解释一下吗?如果是这样,saveMany()将保存许多临时记录。sql调试告诉我引擎正在插入记录而不是更新。您能告诉我如何在活动记录约定中将insert更改为upfate吗?请粘贴一些示例好吗?这不起作用,sql调试只显示以下内容:插入
uat
协议
modified
created
)值('2014-07-01 21:02:49','2014-07-01 21:02:49')。仅更新此字段。
$this->Agreement->save();
$this->Agreement->save($agreements);
$this->Agreement->save($this->request->data);