Cakephp 保存数据,如何将数据应用于所有记录?
我将如何保存以下内容 我希望前4项适用于所有“要保存的产品”,因为这些数据位于我表单的顶部,而“全局”适用于已保存的产品。我如何告诉cakephp将其保存到每个产品,还是必须创建foreach循环并手动插入数据 每个产品的全局数据 控制器中的保存方法Cakephp 保存数据,如何将数据应用于所有记录?,cakephp,cakephp-1.3,cakephp-2.0,Cakephp,Cakephp 1.3,Cakephp 2.0,我将如何保存以下内容 我希望前4项适用于所有“要保存的产品”,因为这些数据位于我表单的顶部,而“全局”适用于已保存的产品。我如何告诉cakephp将其保存到每个产品,还是必须创建foreach循环并手动插入数据 每个产品的全局数据 控制器中的保存方法 $this->Product->saveAll($this->request->data['Product'] 我个人会使用foreach循环,saveAll用于保存相关数据。 e、 g Array ( [Prod
$this->Product->saveAll($this->request->data['Product']
我个人会使用foreach循环,saveAll用于保存相关数据。 e、 g
Array
(
[Product] => Array
(
[discount_id] => 17
[range_id] => 21
[category_id] => 6
[user_id] => 104
[0] => Array
(
[product_code] => ffff
[colour] => red
[lead_time_weeks] =>
[description] =>
[height] => 11111
[width] => 22222
[depth] =>
[price] =>
[discount] => 50
[discounted_price] =>
[quantity] =>
)
[1] => Array
(
[product_code] => fgfgfggf
[colour] => red
[lead_time_weeks] =>
[description] =>
[height] => 123
[width] => 123
[depth] =>
[price] =>
[discount] => 50
[discounted_price] =>
[quantity] =>
)
)
)
$this->Product->saveAll($this->request->data['Product']
foreach($this->request->data['Product'] as $product){
// Don't want to add the generic items
if(is_array($product)){
$newProduct = $this->Product->create();
$newProduct['Product'] = $product; // To save added them seperately
// Then add the generic items into the array
$newProduct['Product']['discount_id'] = $this->request->data['Product']['discount_id'];
etc...
$this->Product->save($newProduct);
}
}