title: CodeIgniter error - Call to a member function on null
body: <p>I have my form which loads login method of Auth controller class on submit and I have AuthData model which has an authenticate function.
  Now when user submits form I get  error?</p>
  
  <p>Warning is-</p>
  
  <blockquote>
    <p>A PHP Error was encountered<br> 
    Severity: Notice<br> 
    Message: Undefined property: Auth::$AuthData<br> 
    Filename: controllers/Auth.php Line Number: 21</p>
    
    <p>Backtrace:<br> 
    File: C:\xampp\htdocs\trials\application\controllers\Auth.php Line: 21 Function: _error_handler<br> 
    File: C:\xampp\htdocs\trials\index.php Line: 315
    Function: require_once<br></p>
    
    <p>Error An uncaught Exception was encountered <br>
    Type: Error <br>
    Message: Call to a member function authenticate() on null <br>
    Filename: C:\xampp\htdocs\trials\application\controllers\Auth.php Line Number: 21 <br></p>
    
    <p>Backtrace: <br>
    File: C:\xampp\htdocs\trials\index.php Line: 315 Function: require_once</p>
  </blockquote>
  
  <p>Here is my controller</p>
  
  <pre><code>&lt;?php
  //defined('BASEPATH') OR exit('No direct script access allowed');
  
  class Auth extends CI_Controller {
  public function index()
  {
      $this-&gt;load-&gt;view('welcome_message');
      $this-&gt;load-&gt;model('AuthData');
      $this-&gt;load-&gt;helper('url');
      // needed ???
      $this-&gt;load-&gt;database();
  }
  
  public function login()
      {
          $user = $this-&gt;input-&gt;post('username');
          $pass = $this-&gt;input-&gt;post('password');
          $input = array( 'username'=&gt;$user, 'password'=&gt;$pass);
  
          $data['loggedIn'] = "no";
          $chk = $this-&gt;AuthData-&gt;authenticate($input);
          if($chk)
              redirect('Sample/success');
          else
              redirect('Sample/failed');
  
  
          //$this-&gt;load-&gt;view('home/contact');
      }   
  }
  </code></pre>
  
  <p>My model</p>
  
  <pre><code>&lt;?php
  //session_start();
  class AuthData extends CI_Model {
  
      public function __construct()
      {
              $this-&gt;load-&gt;database();
      }
  
      public function authenticate($input=NULL)
      {
          $query = $this-&gt;db-&gt;query('SELECT * FROM user');
          $rows = $query-&gt;result_array();
          foreach($rows as $check)
          {
              if($input['password']==$check['password'])
              {
                  if($input['username']==$check['usernmae'])
                  {
                      //session_start();
                      $_SESSION['login'] = "T";
                      $_SESSION['username'] = $input['username'];
                      //is it unsafe to keep password?
                      $_SESSION['password'] = $input['password'];
                      return true;
                      //maybe break here is redundant,but dont want risk
                      break;
                  }
              }
          }
          return false;
      }   
  }
  ?&gt;
  </code></pre>
  
  <p>And form_open in view</p>
  
  <pre><code>&lt;?php echo form_open('auth/login', ['class' =&gt; 'form-signin', 'role' =&gt; 'form']); ?&gt;
  </code></pre>
  
  <p>Also if it matters, I have removed index.php.</p>