开发者

How to send complete POST to Model in Code Igniter

开发者 https://www.devze.com 2023-01-01 03:42 出处:网络
What would be the best way to send a complete post to a model in Code Igniter? Methods I know are as follow:

What would be the best way to send a complete post to a model in Code Igniter? Methods I know are as follow:

Name form el开发者_C百科ements as array, eg.

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

and then use:

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

The other would be to add each element to an 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 of these would be best practice, and is there a way to directly send a whole POST to a model (or a whole form maybe?)


Simply pass $_POST variable to method that you want to work with all POST variables. I see your concern, but rest assured: $_POST is sanitized by security filtering function whenever controller is instantiated.

So:

$this->Model_name->add_contact($_POST);
0

精彩评论

暂无评论...
验证码 换一张
取 消