title: Call to a member function on null error CodeIgniter
body: <p>Please dont`t ask why I have more than one controller: this is what my teacher wants.
  I have 3 controllers: <strong>Api.php</strong>, <strong>Token.php</strong> and <strong>Apikey.php</strong>, where Api.php is the "main" one.</p>
  
  <p><strong>PROBLEM</strong>: When I pass into the <strong>URL</strong>: <a href="http://localhost/revolution/index.php/api/registerUser/first_name/12First" rel="nofollow">http://localhost/revolution/index.php/api/registerUser/first_name/12First</a></p>
  
  <p>it seems there are problems with loading the <strong>Token</strong> controller from <strong>Api</strong> controller.</p>
  
  <p><strong>ERROR:</strong> Fatal error: Call to a member function generateToken() on null</p>
  
  <p>What can I do?</p>
  
  <p>API Controller: <strong>Api.php</strong></p>
  
  <pre><code>class api extends CI_Controller {
  
  
      public function index()
      {
  
          parent::__construct();
          $this-&gt;load-&gt;library("../controllers/Apikey.php");
          $this-&gt;load-&gt;library("../controllers/Token.php");
  
      }
  
      public function registerUser ($username,$parola)
      {
          if ($this-&gt;isValidUserName($username) &amp;&amp; $this-&gt;isValidPass($parola)) {
              $this-&gt;load-&gt;library("../controllers/Token");
              $id = $this-&gt;ApiModel-&gt;insertCredentials($username, md5($parola));
              $this-&gt;Token-&gt;generateToken($id);
              $this-&gt;ApiKey-&gt;generateApiKey($id);
  
              $data['registered'] = 1;
              $this-&gt;load-&gt;view('api', $data);
          }
      }
  }
  </code></pre>
  
  <p>Controller <strong>Token.php</strong></p>
  
  <pre><code> public function existsToken($token)
      {
          $arrayTokens = $this-&gt;ApiModel-&gt;getAllTokens();
  
          if (in_array($token, $arrayTokens))
              return existsToken(sha1($this-&gt;randomString())); //$this-&gt;isValidToken(sha1($this-&gt;randomString()));
  
          return $token;
      }
  
      public function randomString() {
          return intval(993432422 % rand());
      }
  
     public function generateToken($id_user)
      {
          $token = $this-&gt;existsToken(sha1($this-&gt;randomString()));       
          $date = $this-&gt;generateExpDate();
          $result = $this-&gt;ApiModel-&gt;insertToken($token, $date, $id_user);    
      }
  </code></pre>