I am trying to receive a post array send from the view page by using $this->input->post(). However, it seems like that CI is not able to do it. Any thoughts?
controller
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
}
Thanks for help.
UPDATE:
the following is the Jquery code in my view page
//postArray is an array
$.post('<?=base_url()?>/project_detail/pub', {'postArray':postArray},function(go)
{
alert(go);
})
Have you checked your HTML? You should include the
[]synthesis into thenameattribute to create an array, for exampleOutput of
print_r($this->input->post()):If you want to include name keys instead of indexed array, you can use this method:
Output of
print_r($this->input->post()):