How to send full POST to Model in Code Igniter

What would be the best way to send a complete record to a model in Code Igniter? The methods that I know are as follows:

Name form elements like an array, for example.

<input type="text" name="contact[name]"> <input type="text" name="contact[surname]"> 

and then use:

 $this->Model_name->add_contact($this->input->post('contact')); 

Another would be to add each element to the array, and then send it to the model as such:

 <input type="text" name="name"> <input type="text" name="surname"> 

and

 $contact_array = array('name' => $this->input->post('name'), 'surname' => $this->input->post('surname')); $this->Model_name->add_contact($contact_array); 

Which one would be best practice, and is there a way to directly send the entire POST to the model (or maybe the whole form?)

+6
post php codeigniter model
source share
1 answer

Just pass the $ _POST variable to the method that you want to use with all POST variables. I see your concern, but rest assured: $ _POST is sanitized by the security filtering function whenever an instance of the controller is created.

So:

 $this->Model_name->add_contact($_POST); 
+5
source share

All Articles