0
如果已经回答了,但我提前表示歉意,但是我彻底搜索并找不到要查找的内容。Cakephp saveAll不使用相同的字段名称保存多个字段
我有一个具有相同名称的多个输入的表单,但我无法将数据保存到数据库中。
下面是我的表单代码以及我的控制器代码。
在此先感谢。 查理
register_your_card.ctp
echo $this->Form->input('RewardUser.0.reward_card_number', array('label' => '*Card number', 'class' => 'multipleInputs', 'maxlength' => '4'));
echo $this->Form->input('RewardUser.1.reward_card_number', array('label' => '', 'class' => 'multipleInputs', 'maxlength' => '4', 'div' => false));
echo $this->Form->input('RewardUser.2.reward_card_number', array('label' => '', 'class' => 'multipleInputs', 'maxlength' => '4', 'div' => false));
echo $this->Form->input('RewardUser.3.reward_card_number', array('label' => '', 'class' => 'multipleInputs', 'maxlength' => '7', 'div' => false));
RewardUsersController.php
public function register_your_card() {
$this->set('title_for_layout', 'Rewards');
$this->set('meta_keywords', 'Rewards');
$this->set('meta_description', 'Rewards');
if ($this->request->is('post')) {
if (!empty($this->request->data)) {
$this->RewardUser->create(); =
if ($this->RewardUser->saveAll($this->request->data['RewardUser'])) {
$lastInsertID = $this->RewardUser->getLastInsertID();
$this->Session->write('currentUser', $lastInsertID);
return $this->redirect(array('controller' => 'rewardusers', 'action' => 'register_your_card_confirmation'));
}
}
}
}
CakePHP 1.2中有“saveMany”吗? – 2017-07-07 20:49:34