[eluser]Mikeboy[/eluser]
Hi
Quick intro. I am going to rewrite a fairly large database-driven application which was written a few years ago in a spaghetti of php and html. I've researched a number of different MVC frameworks and have decided on CI.
All select, update, and delete queries are achieved through stored procedures (MSSQL).
I notice there are a number of ways to pass the user data to the model. However I am hoping there is a better way that I have missed.
1) Form variables into data array, send data array to model
Code:
View[
<input type="text" name="var1"/>
<input type="text" name="var2"/>
<input type="text" name="var3"/>
Controller
$data['var1'] = $this->input->post('var1');
$data['var2'] = $this->input->post('var2');
$data['var3'] = $this->input->post('var3');
$this->model->add($data);
Model
$v1 = $data['var1'];
$v2 = $data['var2'];
$v3 = $data['var3'];
$this->db->query("exec spXXX '$v1','$v2','$v3'");
The thing I don't like about this method is having to do deal with data[] array in both the model and the controller. Most of the procedures have 10+ parameters so this may be messy.
2) Read the post variables directly from the model. Guess this saves having to read them into the controller first, but, I don't know, I'd rather go through the controller.
Code:
Model
$v1 = $this->input->post('var1');
$v2 = $this->input->post('var2');
$v3 = $this->input->post('var3');
3) Slightly different, .. something like this, from the Godbit tutorial.
Code:
View
<?=form_input($var1);?>
<?=form_input($var2);?>
<?=form_input($var3);?>
Controller
$data["var1"] = array('name' => 'var1', 'id' => 'var1');
$data['var2'] = array('name' => 'var2', 'id' => 'var2');
$data['var3'] = array('name' => 'var3', 'id' => 'var3');
$this->model->add($data);
Model
$v1 = $this->input->post('var1');
$v2 = $this->input->post('var2');
$v3 = $this->input->post('var3');
$this->db->query("exec spXXX '$v1','$v2','$v3'");
Or 4) Something like:
Code:
Controller
$this->model->add($data["var1"], $data["var1"], $data["var1"]);
Model
$this->db->query("exec spXXX '$v1','$v2','$v3'");
Please, can anyone advise the optimum, recommended, most conventional way?!
Edit, I've not included any validation yet - just want to complete the form basics first.
Thanks
Mike