I’m trying to save a long form in Codeigniter’s Datamapper. I’m able to save the form if I pass the value like this
$t->brandName = $this->input->post('brandName');
$t->specialNotes = $this->input->post('specialNotes');
$t->name = $this->input->post('name');
Now if I call save method it works
$t->save();
Since the form is big I tried to add object values in foreach
$a = get_object_vars($t);
foreach ($a['stored'] as $k => $val){
$t->$k = $this->input->post("$k");
}
however if I call the $t->save() it doesn’t work.
I’m not sure what
$a['stored']represents, but it’s nothing that’s default in Datamapper.Why don’t you do it the opposite way, looping through the post keys?
Note: Any columns that don’t exist will just be ignored by Datamapper.
I actually wrote a Datamapper extension for this:
You can use
$t->assign_postdata()->save(), and optionally pass an array of fields to update to the function (in the datamapper validation format). However, I forget why I use that… but I removed some of the custom stuff. This should be useful for you if you are doing this a lot. It definitely saves me time.