title: Codeigniter - accessing variables from an array passed into a page
body: <p>I have a controller with an index function as follows:</p>
  
  <pre><code>function index() 
  { 
      $this-&gt;load-&gt;model('products_model');
      $data['product'] = $this-&gt;products_model-&gt;get(3); // 3 = product id
      $data['product_no'] = 3;
      $data['main_content'] = 'product_view';
      //print_r($data['products']);
      $this-&gt;load-&gt;view('includes/template', $data);
  }
  </code></pre>
  
  <p>This is the get function in the products_model file</p>
  
  <pre><code>function get($id)
  {
      $results = $this-&gt;db-&gt;get_where('products', array('id' =&gt; $id))-&gt;result();
      //get the first item
      $result = $results[0];
      return $result; 
  }
  </code></pre>
  
  <p>The products table contains fields such as name, price etc. Please can you tell me how to output variables from $data['product'] after it is passed into the view?  I have tried so many things but nothing is working, even though the print_r (commented out) shows the data - it is not being passed into the view.  I thought it may have been because the view calls a template file which references the main_content variable:</p>
  
  <p>Template file contents:</p>
  
  <pre><code>&lt;?php $this-&gt;load-&gt;view('includes/header'); ?&gt;
  
  &lt;?php $this-&gt;load-&gt;view($main_content); ?&gt;
  
  &lt;?php $this-&gt;load-&gt;view('includes/footer'); ?&gt;
  </code></pre>
  
  <p>but i tried creating a flat view file and still couldn't access the variables.</p>
  
  <p>Many thanks,</p>