How do you save data from your controllers to your models? |
[eluser]jprateragg[/eluser]
I'm till new to CodeIgniter and still experimenting. I have a question about how everyone inserts data into the database from the controller. This is my controller for creating a new analysis Code: public function create_analysis_2_individual() { In your models, do you insert via Active Record or a standard SQL statement? Do you pass data to the model as parameters: Code: $this->Analysis->create_analysis($member_id, $this->input->post('character_id'), $this->input->post('sic_id'), $this->input->post('import_analysis_id'), $this->input->post('include_member_data')); Or do you send no parameters and simply call the post array at the model level? Code: public function create_analysis() { I'd like to standardize how I insert data, but I don't know if it's possible to always use Active Record (if that is the preferred method).
[eluser]Juan Velandia[/eluser]
1. I would create a function in the model to insert data. And I would call it from the controller 2. I would use Active Record as long as I can. you could check this: http://henrihnr.wordpress.com/2009/04/26...plication/ and really learn a lot.
[eluser]jprateragg[/eluser]
1. That's what I was planning on doing. I was just unsure about how to pass the data to the model method. 2. Thanks for the link. After reading it over, it appears the author prepares an array at the controller and passes that to the model. Code: $person = array('name' => $this->input->post('name'), Is this the best way to prepare data and send it to the controller? Thanks!
[eluser]Juan Velandia[/eluser]
Well to be honest I'm not an expert in CI to decide the "best way". But I always try to create an array with the data to pass to the model and use the $this->db->insert_batch(); so I think you can go with it ... and you can check: http://ellislab.com/codeigniter/user-gui...tml#insert they recomend to use an array for inserting data, so go with it! |
Welcome Guest, Not a member yet? Register Sign In |