开发者

CodeIgniter: Form values to model function

I'm pretty new to the MVC structure and I wan't to do things开发者_Go百科 so close to right as possible. Thats why I ask this question.

I have a form in a view-file. After information has been put into the form and the user have pressed the submit button I wan't to access the information in a function in my model-file.

How do I do this the right way?

Usually, when not using CodeIgniter, i would have done something like this to pass the information to the function:

<?PHP
if(isset($_POST['submit'])){
    $this->the_function($_POST['the_values']);
}
?>

But after read a couple of search hits, what I have come up with, is that this is the wrong way to do it using an MVC pattern. Is that correct?

How should I do it the right way?


The following flow should be followed when handling a form request, which is just like any basic request for any page.

  • Form gets submitted to a controller
  • Controller gets the information via $this->input->get or $this->input->post (these are automatially available by CI, no library/helper loading needed)
  • Controller loads any needed models and acts on the models with this information such as:
    • $this->Comment_Model->get_comments($this->input->get('post_id'));
  • Controller has the information it needs from the model and selects appropriate view
    • $this->load->view('display_comment', $data_from_the_model);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜