![]() |
some doubts about the coding standard - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: some doubts about the coding standard (/showthread.php?tid=43509) |
some doubts about the coding standard - El Forum - 07-13-2011 [eluser]Reneesh T K[/eluser] Hi, I am using codeigniter for past few months. Anyway I have a simple doubt is I am doing it in the right way.. I have searched for a good coding practise.. but didn't get until now. So please let me know is I am doing it in a good way. Suppose view page I have a form with two fields. When submitting the page it is going to the controller function saved_data. for eg the function is class Catalog extends CI_Controller{ function __construct() { parent::__construct(); $this->load->library('form_validation'); $this->load->model('catalog_model'); } function save_data(){ $data['carrier'] = $this->input->post('carrier', TRUE); $data['message'] = $this->input->post('message', TRUE); $productId = $this->catalog_model->insert_db($data); } } Then my model will look like class Catalog_model extends CI_Model { function __construct() { parent::__construct(); } function insert_db($data){ $query = 'INSERT INTO product (carrier, message) VALUES ('.$this->db->escape($data['carrier']).', '. $this->db->escape($data['message']) . ')'; $this->db->query($query); $productId =$this->db->insert_id(); return $productId; } } Now my question is that, do I need to assign the posted values to the $data array in the controller? I think this is losing my time as I need to store the posted values to an array in the controller and pass it to the model for insert to db.. I can directly get the posted values in the model.. then why I need to store it in data array and pass it to model.. Let me know your thinking about this.. some doubts about the coding standard - El Forum - 07-14-2011 [eluser]cahva[/eluser] Yeah, that way there is repetition. You can use $this->input->post in model straight but I would do it differently. In model I would have this: Code: function insert_db($data) |