title: Class methods and instance methods in codeigniter, how can I use them?
body: <p>I am very new to codeigniter but understand OOP and MVC as I do a lot of Rails development.  One thing I haven't figured out yet is how to write a class level method in codeigniter and access it in a controller.  For example, I have</p>
  
  <pre><code>&lt;?php
  class User_model extends Model {
      function user_model()
      {
          parent::Model();
      }
  
      public static function get_total_users_count(){
          $results = $this-&gt;db-&gt;query("SELECT * FROM bhr_users GROUP BY userid");
          if($results){
              return $results-&gt;num_rows();
          }
          return 0;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>I think what I have done here is established a class level method for my model that I should be able to call with <code>User_model::get_total_users_count()</code> Now in my controller which a previous programmer called "Welcome" I have something like:</p>
  
  <pre><code>&lt;?php
  
  class Welcome extends Controller {
  
      function Welcome()
      {
          parent::Controller();   
          $this-&gt;load-&gt;model('bhr_model');
              $this-&gt;load-&gt;model('user_model');
      }
  
      function index()
      {
  
          $invite =    $this-&gt;uri-&gt;segment(3);
          if($invite == 'invitefriends') {
              $pagedata['invitefriends'] = $invite;
          } else {
              $pagedata['invitefriends'] = '';
          }
  
          $pagedata['numberofpeople'] = User_model::get_total_users_count();
          $this-&gt;load-&gt;view('default_page', $pagedata);
      }
  }
  </code></pre>
  
  <p>The above method call to <code>get_total_users_count</code> does not work because it says because I am using the db method on a class level function in <code>get_total_users_count</code>.  In other words $this has no db method when I reference a class.  </p>
  
  <p>So now my question is a bit more theoretical.  I always thought that instance methods should only be used when a method is acting on a specific instance of an class.  Makes sense, right?  However, <code>get_total_users_count</code> is acting on all "users" and counting them.  It just seems like that should be a class level method.  Do you agree?  If do, do you know how I can access the database from withing the framework inside a class level function?</p>
  
  <p>Thanks!</p>