Welcome Guest, Not a member yet? Register   Sign In
Passing data to a model as array
#1

[eluser]Corbee[/eluser]
Hi,

Just wondering is it possible to make this an array

Code:
$sessionid = getSessionID();
            $example1= $this->input->post('example1');
            $example2= $this->input->post('example2');
            $example3= $this->input->post('example3');
            $example4= $this->input->post('example4');
            $example5= $this->input->post('example5');
            
$this->MExample->insertexample(example1,example2,example3,example4,example5);

Like put all the post into $data[] then pass it to the database like this

Code:
$this->MExample->insertexample($data);

so that I could pass it to another parts of the function, such as loading the view

Code:
$this->load->view('example',$data);

Thanks
#2

[eluser]smilie[/eluser]
Code:
$data = array($this->input->post('example1'),$this->input->post('example2'),$this->input->post('example3'),$this->input->post('example4'),$this->input->post('example5'));

$this->MExample->insertexample($data);

Untested, but should work.

Regards,
Smilie
#3

[eluser]_krc_[/eluser]
Why not just set the $_POST as an argument into model and then retrieve by index inside model.
#4

[eluser]smilie[/eluser]
One of reasons I could think of is because $this->input->post() filters for malicious data in your post, so avoiding it creates some risk.

Regards,
Smilie
#5

[eluser]Nick_MyShuitings[/eluser]
You could also do a foreach of post.

Code:
foreach($_POST as $key => $value){
$newarray[$key]=$this->input->post($value);
}

Would get the benefit o having it auto as well as the filtering of the input class.

Note: untested example written in an iPod.




Theme © iAndrew 2016 - Forum software by © MyBB