title: CodeIgniter, pass data from model to controller to use in view
body: <p>I want to pass data queried in my model to the controller, to do so I am using return $data. Then in the controller I use <code>$this-&gt;load-&gt;view('my_view', $data);</code></p>
  
  <p>From my understanding <code>var_dump($data);</code> in the view should show me the results from the query... This is not the case. I am getting "undefined variable data" and NULL from the <code>var_dump($data);</code>.</p>
  
  <p>Here is my model:</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Manage_accounts_model extends CI_Model {
  
  
      public function index() {
  
          //
  
      }
  
      public function get_users(){
  
          $data = array();
  
          $data['query'] = $this-&gt;db-&gt;get('users');
  
          return $data['query'];
  
       }
  
  }
  </code></pre>
  
  <p>Here is my controller</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Manage_accounts extends CI_Controller {
  
      public function index() {
  
          $this-&gt;load-&gt;view('template/header');
  
          $this-&gt;load-&gt;model('manage_accounts_model');
  
          $this-&gt;load-&gt;view('template/footer');
  
          $this-&gt;load-&gt;model('manage_accounts_model');
  
          $res = $this-&gt;manage_accounts_model-&gt;get_users();
  
          if($res){
  
              $this-&gt;load-&gt;view('manage_accounts_view', $data);
  
          } else {
  
              echo "Fail";
  
          }
  
    }
  
  }
  </code></pre>
  
  <p>And finally my view:</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  ?&gt;
  &lt;div class="container"&gt;
  
      &lt;h1&gt;&lt;?php if($title){ echo $title; } ?&gt;&lt;/h1&gt;
  
      &lt;?php var_dump($data['query']); ?&gt;
  
  &lt;/div&gt;
  </code></pre>