我在使用update_batch发布时收到此错误.我已经看到了其他帖子,但我的行引用是DB_active_rec.php文件,其他人在他们的MC中看到它.该错误不会阻止update_batch发布,它会返回每个$ rb_items的错误.

控制器:
public function update_rb(){
$rb_items = array();
$rb_id=$this->input->post('id', TRUE);
$rb_brand=$this->input->post('brand', TRUE);
$rb_tasted=$this->input->post('tasted', TRUE);
$rb_rating=$this->input->post('rating', TRUE);
$rb_comment=$this->input->post('comment', TRUE);
$i=0;
foreach($rb_id as $id){
$rb_items[$i] = array(
'id'=>$id,
'brand'=>$rb_brand[$i],
'rating'=>$rb_rating[$i],
'comment'=>$rb_comment[$i]
);
if(empty($rb_tasted)){
$rb_items[$i]['tasted']=0;
} else if
(in_array($id,$rb_tasted)){
$rb_items[$i]['tasted']=1;
} else{
$rb_items[$i]['tasted']=0;
}
$i++;
}
$this->model->update_rb($rb_items);
}
Run Code Online (Sandbox Code Playgroud)
模型:
public function update_rb($rb_items){
$this->rb_db->update_batch('rb_selection',$rb_items,'id');
}
Run Code Online (Sandbox Code Playgroud)
视图:
<tr>
<input type="hidden" name="id[]" value="<?php echo $row['id'];?>">
<input type="hidden" name="brand[]" value="<?php echo $row['brand'];?>">
<td><?php echo "<p>".$row['brand']."</p>";?></td>
<td><input type="checkbox" <?php if($row['tasted'] == 1){echo "checked = checked";}?> name="tasted[]" value="<?php echo $row['id'];?>" id="tasted"/></td>
<td><input type="text" name="rating[]" <?php echo $row['rating'];?>/></td>
<td><textarea name='comment[]' id='comment' cols="350"><?php echo $row['comment'];?></textarea></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
有没有人看到这个错误或知道我的代码中缺少什么?谢谢您的帮助!
print_r($rb_items)返回Array ( [0] => Array ( [rb_id] => 192 [brand] => Napa Valley Soda Co [rating] => r0 [comment] => c0 [tasted] => 1 ) [1] => Array ( [rb_id] => 193 [brand] => Natural Brew [rating] => r1 [comment] => c1 [tasted] => 1 ) [2] => Array ( [rb_id] => 194 [brand] => Naturale 90 [rating] => r2 [comment] => c2 [tasted] => 1 ) )
包含三个品牌的视图.无论错误如何,所有这些都是正确发布的.
viz*_*ata 13
我的CI版本存在问题,即2.1.2.在第1407行的DB_active_rec.php文件中,
这个:
$not[] = $k.'-'.$v;
应该:
$not[] = $k2.'-'.$v2;
在这里找到了正确的答案:https: //stackoverflow.com/a/12910038/1738895