CakePhp 多个请求
CakePhp Multiple Requests
我需要保存多个请求。现在我有这样的东西:
if($this->Request->save($tmp))
if($this->Request->save($tmp2)){code;}
$tmp2 覆盖 $tmp。如何拯救他们两个? (1 乘 1)
如果你想将多行一一保存到同一个模型你需要使用
$this->model_name->create();
在每次保存之前,否则它会创建一个而其他保存只会更新第一行(如果主键不包含在您要使用的数组中)。
首先你不能在没有指定模型的情况下保存请求数据。您只能将数据保存到模型中。所以你应该使用 $this->model_name->save($this->request->data) 而不是 $this->request->save。 Request 是 cake php.
中的处理程序
你应该试试。
$this->model1->save($this->request->data["model1"]);
$this->model2->save($this->request->data["model2"]);
别忘了分享结果。如果你在模型中建立了关系,那么你可以使用 cakephp 的 saveAll().
我需要保存多个请求。现在我有这样的东西:
if($this->Request->save($tmp))
if($this->Request->save($tmp2)){code;}
$tmp2 覆盖 $tmp。如何拯救他们两个? (1 乘 1)
如果你想将多行一一保存到同一个模型你需要使用
$this->model_name->create();
在每次保存之前,否则它会创建一个而其他保存只会更新第一行(如果主键不包含在您要使用的数组中)。
首先你不能在没有指定模型的情况下保存请求数据。您只能将数据保存到模型中。所以你应该使用 $this->model_name->save($this->request->data) 而不是 $this->request->save。 Request 是 cake php.
中的处理程序你应该试试。
$this->model1->save($this->request->data["model1"]);
$this->model2->save($this->request->data["model2"]);
别忘了分享结果。如果你在模型中建立了关系,那么你可以使用 cakephp 的 saveAll().