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