插入替换为codeigniter和多个复选框

时间:2018-08-28 07:20:49

标签: php codeigniter checkbox

我正在一个项目中,在该项目中,我基于用户组进行访问,但是在进行多次插入时遇到问题。 问题是如何通过插入替换从复选框中向数据库输入值

查看

<tr>
    <td class='mail-select'>
        <i class='fa fa-angle-right m-r-15 text-muted'></i>
        <a href='email-read.html' class='email-name'>".$s->name."</a>
        <input name='id_menu[]' value='".$s->id."' type='hidden'>
    </td>
    <td>
        <div class='checkbox checkbox-primary m-r-15'>
            <input name='read[]' value='Y' id='R-".$s->id."' type='checkbox'>
            <label for='R-".$s->id."'></label>
        </div>
    </td>
    <td>
        <div class='checkbox checkbox-primary m-r-15'>
            <input name='create[]' value='Y' id='C-".$s->id."' type='checkbox'>
            <label for='C-".$s->id."'></label>
        </div>
    </td>
    <td>
        <div class='checkbox checkbox-primary m-r-15'>
            <input name='update[]' value='Y' id='U-".$s->id."' type='checkbox'>
            <label for='U-".$s->id."'></label>
        </div>
    </td>
    <td>
        <div class='checkbox checkbox-primary m-r-15'>
            <input name='delete[]' value='Y' id='D-".$s->id."' type='checkbox'>
            <label for='D-".$s->id."'></label>
        </div>
    </td>
</tr>

CONTROLLER

public function addRole()
{
    $group  = $this->input->post('group');
    $num    = $this->input->post('num');
    $id_menu= $this->input->post('id_menu[]');
    $read   = $this->input->post('read[]'); 
    $create = $this->input->post('create[]');   
    $update = $this->input->post('update[]');   
    $delete = $this->input->post('delete[]');   

        for ($i=0;$i<$num;$i++){
         $data = array(
            'group_id' => $group, 
            'menu_id'  => $id_menu[$i],
            'index'    => $read[$i],
            'add'      => $create[$i],
            'edit'     => $update[$i],
            'delete'   => $delete[$i],

             );
            $role =  $this->db->insert_batch('box_role', $data);
        }
    redirect("auth/role", 'refresh');
}

1 个答案:

答案 0 :(得分:0)

没有replace_batch。您可以自己编写代码或打开交易,删除所有寄存器,再次插入代码,然后提交交易。