我必须在添加表单(控制器)中使用相同的多行,但它没有保存多个记录。我是否必须在foreach下移动保存?或者我可以做些什么来保存多行?
$boldNumberRequest = $this->BoldNumberRequest->newEntity();
$boldNumberRequest = $this->BoldNumberRequest->patchEntity($boldNumberRequest, $this->request->data);
$this->BoldNumberRequest->saveMany($boldNumberRequest)
这是我在$ this-> request-> data
中获得的内容(int) 0 => [
'bold_number_from' => '1',
'bold_number_to' => '1000',
'is_approved' => '1',
'unique_series' => '030318',
'owner_company_id' => '1'
],
(int) 1 => [
'bold_number_from' => '1',
'bold_number_to' => '1000',
'is_approved' => '1',
'unique_series' => '100318',
'owner_company_id' => '1'
],
答案 0 :(得分:2)
您的问题是您使用$this->BoldNumberRequest->newEntity()
创建单个实体,然后尝试使用多个实体的数据修补它。
您可以在关于Saving Multiple Entities的CakePHP文档中找到您想要的内容:
您需要从数据中创建多个实体:
$entities = $this->BoldNumberRequest->newEntities($this->request->data);
$this->BoldNumberRequest->saveMany($entities);