title: Codeigniter passing data from controller to view
body: <p>As per <a href="http://codeigniter.com/user_guide/general/views.html">here</a> I've got the following controller:</p>
  
  <pre><code>class User extends CI_Controller {
      public function Login()
      {
          //$data-&gt;RedirectUrl = $this-&gt;input-&gt;get_post('ReturnTo');
          $data = array(
                 'title' =&gt; 'My Title',
                 'heading' =&gt; 'My Heading',
                 'message' =&gt; 'My Message'
            );
          $this-&gt;load-&gt;view('User_Login', $data);
      }
  
      //More...
  }
  </code></pre>
  
  <p>and in my <code>User_Login.php</code> view file I do this:</p>
  
  <pre><code>&lt;?php print_r($data);?&gt;
  </code></pre>
  
  <p>which results in:</p>
  
  <pre><code>A PHP Error was encountered
  Severity: Notice
  Message: Undefined variable: data
  Filename: views/User_Login.php
  Line Number: 1
  </code></pre>
  
  <p>Do I need to load any specific modules/helpers to get the $data variable populated? If I <code>print_r($this)</code>, I can see a lot of stuff but none of my data except in caches</p>
  
  <p>Edit: To clarify, I know that calling the variable the same in the controller and view won't "share" it - it's out of scope but in the example I linked, it seems to imply a <code>$data</code> variable is created in the scope of the view. I simply happened to use the same name in the controller</p>