脚本应该在数据库中创建 3 个条目,但我只得到一个,它是最后一个条目。
在我看来 save() 方法只执行一次,但它不应该像在 for 循环中一样运行 3 次吗?
public function saveAction()
{
$vars = $this->getRequest()->getPost();
var_dump($vars);
$model = mage::getModel('cevent/cevent');
for($i=0;$i<=2;$i++){
$data = array(
'master_customer_id' => $vars['master_customer_id'][$i],
'customer_id' => 'null',
'email' => $vars['email'][$i],
'firstname' => $vars['firstname'][$i],
'surname' => $vars['surname'][$i],
'address' => $vars['address'][$i],
'city' => $vars['city'][$i]
);
$model->addData($data);
$model->save();
}
}
数据库表单中的已发布数据
array
'master_customer_id' =>
array
0 => string '1' (length=1)
1 => string '1' (length=1)
2 => string '1' (length=1)
'firstname' =>
array
0 => string 'q' (length=1)
1 => string 'w' (length=1)
2 => string 'e' (length=1)
'surname' =>
array
0 => string 'q' (length=1)
1 => string 'w' (length=1)
2 => string 'e' (length=1)
'email' =>
array
0 => string 'q' (length=1)
1 => string 'w' (length=1)
2 => string 'e' (length=1)
'address' =>
array
0 => string 'Invercagille' (length=12)
1 => string 'Invercagille' (length=12)
2 => string 'Invercagille' (length=12)
'city' =>
array
0 => string 'q' (length=1)
1 => string 'w' (length=1)
2 => string 'e' (length=1)
数据库只显示一个条目
请提出一些建议,或者是否有其他方法。谢谢