title: Codeigniter: One view for adding and editing a post
body: <p>I'm working on a CMS in Codeigniter and one main part is a form for creating and editing posts.</p>
  
  <p>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?</p>
  
  <p>I was thinking about having a method for each, so post/create and post/edit($id).</p>
  
  <p>In the create method in the post controller I have all the form data like this (for errors):</p>
  
  <pre><code>  $this-&gt;data['item_title'] = array(
      'name' =&gt; 'item_title',
      'id' =&gt; 'item_title',
      'type' =&gt; 'text',
      'value' =&gt; $this-&gt;form_validation-&gt;set_value('item_title'),
    );
  </code></pre>
  
  <p>I'm thinking about just altering the value to hold the database value instead of set_value(), so something like:</p>
  
  <pre><code>public function edit($id) {
  
  $post_data = $this-&gt;post_model-&gt;get_post_data($id)
  
        $this-&gt;data['item_title'] = array(
          'name' =&gt; 'item_title',
          'id' =&gt; 'item_title',
          'type' =&gt; 'text',
          'value' =&gt; $post_data['post_title'],
        );
  }
  </code></pre>
  
  <p>Am I on the right track or is there a better way to approach this? Should I just use 2 views?</p>