title: code igniter question: problem with passing variable to a view
body: <p>I am a newbie with CodeIgniter (2.03), and I have the following problem:</p>
  
  <p>Here is my main template (view):</p>
  
  <pre><code>&lt;?php $this-&gt;load-&gt;view('backOffice/bo_header_in'); ?&gt;
  
  &lt;?php $this-&gt;load-&gt;view($bo_main_content); ?&gt;
  
  &lt;?php $this-&gt;load-&gt;view('backOffice/bo_footer_in'); ?&gt;
  </code></pre>
  
  <p>Here is my model:</p>
  
  <pre><code>&lt;?php
  
  class Back_office_users extends CI_Model 
  {
  
    public function getAllUsers () 
    {
      $query = $this-&gt;db-&gt;query("SELECT * FROM users");
  
      if ($query-&gt;num_rows() &gt; 0) {
        foreach ($query-&gt;result() as $rows) {
          $users[] = $rows;
        }
        return $users; 
      }
    }
  }  
  </code></pre>
  
  <p>And here is my controler:</p>
  
  <pre><code>&lt;?php
  
  class Dashboard extends CI_Controller 
  {
  
    public function __construct() 
    {
      parent::__construct();
      $this-&gt;is_logged_in();
    }
  
    public function index () 
    {   
      $this-&gt;load-&gt;model('back_office_users');
      $users['rows'] = $this-&gt;back_office_users-&gt;getAllUsers();
  
      $data['bo_main_content'] = "backOffice/dashboard";
  
      $this-&gt;load-&gt;view('backOffice/bo_template_in', $data, $users);
  
     // if I pass the variable like this it works just fine...
     //$this-&gt;load-&gt;view('backOffice/users', $users);
    }
  
    public function is_logged_in()
    {
      $is_logged_in = $this-&gt;session-&gt;userdata('is_logged_in');
      if (!isset($is_logged_in) || ($is_logged_in != true)) {
        $this-&gt;accessdenied();   
      }
    }
  
    public function accessdenied () 
    {    
      $data['bo_main_content'] = 'backOffice/accessdenied';
      $this-&gt;load-&gt;view('backOffice/bo_template', $data);
    }
  
    public function logout () 
    {    
      $this-&gt;session-&gt;sess_destroy();
      redirect('backOffice/index');
    }
  }  
  </code></pre>
  
  <p>And the dashboard view is like this:</p>
  
  <pre><code>&lt;?php
    print_r($users);
  ?&gt; 
  </code></pre>
  
  <p>I am getting the following error:</p>
  
  <blockquote>
    <p>A PHP Error was encountered</p>
    
    <p>Severity: Notice</p>
    
    <p>Message: Undefined variable: users</p>
    
    <p>Filename: backOffice/dashboard.php</p>
    
    <p>Line Number: 9</p>
  </blockquote>
  
  <p>Can anyone shed some light how can I resolve this? I create another view without use of the template, and it print the array.</p>