I'm working on a CMS in Codeigniter and one main part is a form for creating and editing posts.
I've been planning on using the same view file for both since all of the elements are shared. The only difference would be the form is blank when creating and it's populated when being edited. Is this the right way to go?
I was thinking about having a method for each, so post/create and post/edit($id).
In the create method in the post controller I have all the form data like this (for errors):
$this->data['item_title'] = array(
'name' => 'item_title',
'id' => 'item_title',
'type' => 'text',
'value' => $this->form_validation->set_value('item_title'),
);
I'm thinking about just altering the value to hold the database value instead of set_value(), so something like:
public function edit($id) {
$post_data = $this->post_model->get_post_data($id)
$this->data['item_title'] = array(
'name' => 'item_title',
'id' => 'item_title',
'type' => 'text',
'value' => $post_data['post_title'],
);
}
Am I on the right track or is there a better way to approach this? Should I just use 2 views?