【发布时间】:2016-05-07 12:55:40
【问题描述】:
我需要将 id 值从视图传递到控制器,但我有 2 个选项
- 使用带有 uri 段的锚标记 2.带隐藏字段形式
我觉得两者都不能用,如果可以的话请指导我
<?php for($i=0;$i<count($array['value']);$i++) { ?>
<?php $id= $array['value'][$i]['arrayIndex']; ?>
echo form_open('controller/array_storage/'.$id)
<input type="hidden" name="<?php echo 'foo'.$i ?>" value="<?php echo $array['value'][$i]['foo']?>" />
<input type="hidden" name="<?php echo 'boo'.$i?>" value="<?php echo $array['value'][$i]['boo']?>" />
<input type="hidden" name="<?php echo 'bar'.$i?>" value="<?php echo $array['value'][$i]['bar']?>" />
<input type="submit">
<? } ?>
这是我的控制器
<?php
function array_storage($id)
{
$foo = $this->input->post('foo'.$id);
$boo = $this->input->post('boo'.$id);
$bar = $this->input->post('bar'.$id);
}
?>
这是我的数组
array(4) { ["aa"]=> int(12) ["b"]=> string(4) "2222" ["c"]=> string(3) "232" ["array"]=> array(4) { [0]=> array(7) { ["test"]=> string(5) "23132" ["aaa"]=> int(131) ["bbb"]=> string(4) "sgsg" ["ccc"]=> string(6) "qweqrq" ["ddd"]=> NULL ["eee"]=> int(0) ["value"]=> array(4) { ["foo"]=> int(46546) ["boo"]=> string(6) "231231" ["bar"]=> string(4) "test" ["TDS"]=> string(3) "0.0" } } [1]=> array(7) { ["test"]=> string(5) "23132" ["aaa"]=> int(131) ["bbb"]=> string(4) "sgsg" ["ccc"]=> string(6) "qweqrq" ["ddd"]=> NULL ["eee"]=> int(0) ["value"]=> array(4) { ["foo"]=> int(46546) ["boo"]=> string(6) "231231" ["bar"]=> string(4) "test" ["TDS"]=> string(3) "0.0" } } [2]=> array(7) { ["test"]=> string(5) "23132" ["aaa"]=> int(131) ["bbb"]=> string(4) "sgsg" ["ccc"]=> string(6) "qweqrq" ["ddd"]=> NULL ["eee"]=> int(0) ["value"]=> array(4) { ["foo"]=> int(46546) ["boo"]=> string(6) "231231" ["bar"]=> string(4) "test" ["TDS"]=> string(3) "0.0" } } [3]=> array(7) { ["test"]=> string(5) "23132" ["aaa"]=> int(131) ["bbb"]=> string(4) "sgsg" ["ccc"]=> string(6) "qweqrq" ["ddd"]=> NULL ["eee"]=> int(0) ["value"]=> array(4) { ["foo"]=> int(46546) ["boo"]=> string(6) "231231" ["bar"]=> string(4) "test" ["TDS"]=> string(3) "0.0" } } } }
帮我解决问题
转换后的 json 以方便查看
{
"aa": 12,
"b": "2222",
"c": "232",
"array": [
{
"arrayIndex": "1",
"aaa": 131,
"bbb": "sgsg",
"ccc": "qweqrq",
"ddd": null,
"eee": 0,
"value": {
"foo": 46546,
"boo": "231231",
"bar": "test",
"TDS": "0.0"
}
},
{
"arrayIndex": "2",
"aaa": 131,
"bbb": "sgsg",
"ccc": "qweqrq",
"ddd": null,
"eee": 0,
"value": {
"foo": 46546,
"boo": "231231",
"bar": "test",
"TDS": "0.0"
}
},
{
"arrayIndex": "3",
"aaa": 131,
"bbb": "sgsg",
"ccc": "qweqrq",
"ddd": null,
"eee": 0,
"value": {
"foo": 46546,
"boo": "231231",
"bar": "test",
"TDS": "0.0"
}
},
{
"arrayIndex": "4",
"aaa": 131,
"bbb": "sgsg",
"ccc": "qweqrq",
"ddd": null,
"eee": 0,
"value": {
"foo": 46546,
"boo": "231231",
"bar": "test",
"TDS": "0.0"
}
}
]
}
【问题讨论】:
-
尽可能发布您的完整数组...
-
这是我的示例数组的样子
-
您似乎忘记在表单操作
<?php echo form_open("controller/array_storage/$id"); ?>中输入$id。 (您在这里拼错了 controller 字)。 -
我也试过,但 $id 总是返回值 1
-
echo form_open('controller/array_storage/'.$id)
标签: php codeigniter