How to pass a variable from model to controller in codeigniter
<p>How can I pass a variable from the model to the controller?</p>

<p>Here is my model:</p>

<pre><code>public function edititem($id){
$query = $this-&gt;db-&gt;query('SELECT * FROM tblitem WHERE item_id = "$id"');

foreach ($query-&gt;result() as $row){
    $name = $row-&gt;item_name;
    $description = $row-&gt;item_description;
    $price = $row-&gt;item_price;

}
</code></pre>

<p>And here is my controller</p>

<pre><code>public function editItem(){
      $this-&gt;load-&gt;helper('form');
      $this-&gt;load-&gt;model('ItemModel');
      $this-&gt;ItemModel-&gt;edititem($this-&gt;input-&gt;get('id'));

      $name = $this-&gt;input-&gt;post('name');
      $description = $this-&gt;input-&gt;post('description');
      $price = $this-&gt;input-&gt;post('price');

      $data['items'] = $this-&gt;ItemModel-&gt;itemlist();

      $this-&gt;load-&gt;view('item/item_edit',$data);
</code></pre>

<p>}</p>

<p>In which when the user clicks "Edit Item", it will populate the form with the selected row.</p>

<pre><code>&lt;form action="&lt;?php echo base_url().'item/edititem' ?&gt; " method="post"&gt;
       &lt;div class="form-group"&gt;
            &lt;label for="name"&gt;Name&lt;/label&gt;
            &lt;input type="name" class="form-control" id="name" name="name" placeholder="Name" value="&lt;?php echo set_value('name'); ?&gt;"&gt;
       &lt;/div&gt;
       &lt;div class="form-group"&gt;
            &lt;label for="description"&gt;Description&lt;/label&gt;
            &lt;textarea class="form-control" rows="3" name="description"&gt;&lt;?php echo set_value('description'); ?&gt;&lt;/textarea&gt;
       &lt;/div&gt;

       &lt;div class="form-group"&gt;
            &lt;label class="sr-only" for="price"&gt;Amount (in pesos)&lt;/label&gt;
            &lt;div class="input-group"&gt;
                  &lt;div class="input-group-addon"&gt;Php&lt;/div&gt;
                  &lt;input type="text" class="form-control" name="price" id="price" placeholder="Amount" value="&lt;?php echo set_value('price'); ?&gt;"&gt;
                  &lt;div class="input-group-addon"&gt;.00&lt;/div&gt;
            &lt;/div&gt;
      &lt;/div&gt;
      &lt;button type="submit" class="btn btn-primary"&gt;EDIT ITEM&lt;/button&gt;
&lt;/form&gt;
</code></pre>