Fly*_*Cat 1 arrays post codeigniter
我试图通过使用$ this-> input-> post()从视图页面接收发布数组.但是,似乎CI无法做到这一点.有什么想法吗?
调节器
public function pub()
{
// the postArray is an array: $postArray['t1']=test1, $postArray['t2']=test2
$go=$this->input->post('postArray');
foreach ($go as $test){
echo $test['t1']; //show nothing
echo $test['t2']; //show nothing
}
//the following code would work if I sent the $postArray as a string variable
public function pub()
{
// the postArray is an string variable $postArray='test1'
$go=$this->input->post('postArray');
echo $go; //show test1
}
Run Code Online (Sandbox Code Playgroud)
感谢帮助.
更新:以下是我的视图页面中的Jquery代码
//postArray is an array
$.post('<?=base_url()?>/project_detail/pub', {'postArray':postArray},function(go)
{
alert(go);
})
Run Code Online (Sandbox Code Playgroud)
你检查过你的HTML了吗?例如,您应该将[]合成包含在name属性中以创建数组
<input type="text" value="something..." name="postArray[]" />
<input type="text" value="something..." name="postArray[]" />
Run Code Online (Sandbox Code Playgroud)
产量print_r($this->input->post()):
Array (
[0] => something...
[1] => something...
)
Run Code Online (Sandbox Code Playgroud)
如果要包含名称键而不是索引数组,可以使用此方法:
<input type="text" value="something..." name="postArray[t1]" />
<input type="text" value="something..." name="postArray[t2]" />
Run Code Online (Sandbox Code Playgroud)
产量print_r($this->input->post()):
Array (
[t1] => something...
[t2] => something...
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4074 次 |
| 最近记录: |