[eluser]Wazzu[/eluser]
Hi, all. This is a newbie question about Datamapper.
My code is working but I'm not sure if this is the right way.
Imagine I have a users table (id, name), a phones table (id, number) an a relation table called users_phones (user_id, phone_id)
I want to use the same form to add and edit, so I'm doing this way:
From the controller
Code:
function form() {
$u = new User();
$t = new Phone();
if($this->input->post('add')) {
$u->name = $this->input->post('name');
$t->number = $this->input->post('number');
$t->save();
$u->save($t);
}
$this->load->view('form');
}
And from the view
Code:
<input name="name" value="<?php echo $u->name ?>">
<input name="number" value="<?php echo $t->number ?>">
Q1 Up to here, is this the correct procedure to save it? or I should use only one model?
Q2 How can I reuse this form to edit an existing record?
Thanks in advance