CodeIgniter:从表单数组获取数据到post数组

mdv*_*sta 2 php arrays post codeigniter

我在绞尽脑汁.我正在使用CodeIgniter,尝试从表单复选框获取值到数据数组以发送到数据库.以下是片段:

表格(查看):

<label>Rental Car?</label><input type="checkbox" name="options[is_rental]" value="1" <?php echo set_checkbox('options[is_rental]', '1', FALSE); ?> />
Run Code Online (Sandbox Code Playgroud)

控制器:

$data['is_rental'] = $this->input->post('options[is_rental]');
Run Code Online (Sandbox Code Playgroud)

现在,在此过程中,我还使用选项[is_rental]验证并使用数据重新填充表单,并且工作得很好.使用var_dump我得到:

从控制器转储(选中复选框):

var_dump($this->input->post('options[is_rental]'))
Run Code Online (Sandbox Code Playgroud)

返回

bool(false)
Run Code Online (Sandbox Code Playgroud)

和...

var_dump($this->input->post('options'))
Run Code Online (Sandbox Code Playgroud)

返回

array(3) { ["engine"]=> string(4) "4cyl" ["transmission"]=> string(9) "automatic" ["is_rental"]=> string(1) "1" }
Run Code Online (Sandbox Code Playgroud)

对于它的价值,我也无法获得数组中的其他值.

phi*_*bar 8

为什么不这样做:

$ data = $ this-> input-> post('options');

那么$ data ['is_rental']应该== 1