Is accessing post values directly in a model a good idea? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Is accessing post values directly in a model a good idea? (/showthread.php?tid=34806) |
Is accessing post values directly in a model a good idea? - El Forum - 10-10-2010 [eluser]zrowcrypt[/eluser] Both ways work but I am more interested to know which one is good practice : 1. Somecontroller.php $name = $this->input->post['name']; $this->load->model('somemodel'); $this->somemodel->modelfunction($name); Vs 2 Somemodel_model.php function modelfunction() { $name = $this->input->post['name']; ... } Should models be directly accessing values from the view(post data)? Isnt it better that controller passes the data and controls what model gets from the views? I am very new to MVC so still picking up concepts so pardon me if my question are a little silly. Thanks, Vikas Is accessing post values directly in a model a good idea? - El Forum - 10-10-2010 [eluser]zrowcrypt[/eluser] 25 views and no answer yet . Is there something fundamentally wrong with my question? Is accessing post values directly in a model a good idea? - El Forum - 10-10-2010 [eluser]Buso[/eluser] Sometimes I use $_POST directly in the models.. But I guess we'll have to wait for an MVC guru or something =P Is accessing post values directly in a model a good idea? - El Forum - 10-10-2010 [eluser]Jelmer[/eluser] This is one of those questions where there pretty much isn't a right answer. I like to make this possible as well because it does save some duplicate code, on the other hand I might need to edit stuff in a way that I can't just call the model and let it handle the post. My advice: make it possible to do it both with post and with passing variables. I tend to let my models do the validation work as well and I don't always need full validation, sometimes just a couple of fields. At the same time not all fields can always be used from post directly (to keep things simple for users). I've solved this by calling from the controller like this (fake example): Code: $fields = array( And the Email_address model has the following: Code: protected $fields_validation = array( I think you can get the idea? |