[eluser]ch5i[/eluser]
Hello Moobies,
totally agree with you.
With the pre-1.7 validation library I used prefill forms for editing like this:
Controller
Code:
...
$this->load->library('validation');
// set rules
$rules['firstname'] = 'trim|max_length[45]|required';
$this->validation->set_rules($rules);
// set default value
$this->validation->firstname = $this->user->firstname;
// run validation
// if post field 'firstname' is set, it will overwrite the
// value set above
if ( ! $this->validation->run()) {
// did not pass validation, or first run
$this->load->view('user/forms/user_add_edit');
} else {
// validation passed, fetch new values and save
$this->user->firstname = $this->validation->firstname);
$this->user->save();
}
...
View
Code:
...
<input type="text" name="firstname" value="<?= $this->validation->firstname ?>" />
...
This has been working very well, and I could keep my views relatively clean. I like to have as little php as possible in the views.
I wonder how this is supposed to be done 'correctly' with the new validation library...?
Until something better comes up, I think I'll go with your approach.
Thanks a lot for sharing.