title: Object Oriented Approach in Codeigniter Model
body: <p>I have been wondering what is the right way to write code in OO style in model. Certainly you can have a function that retrieve data from DB and then map to model-level variables. This approach, however, becomes counterintuitive when you have other function in model trying to get other data from BD. For example:</p>
  
  <pre><code>class User extends CI_Model {
      $id, $name, $age .... ;
  
      public function get_user_from_db_with_id($id) {
          ...
          // get data and map to variable. 
      } 
  
      public function get_all_users() {
      // return all users in db
      }
  
  }
  </code></pre>
  
  <p>somewhere in controller:</p>
  
  <pre><code>$user = new User();
  $ben = $user-&gt;get_user_from_db_with_id($id);
  
  // this does not make sense!! 
  $all_user = $ben-&gt;get_all_users();
  </code></pre>
  
  <p>Any thought or comment?</p>
  
  <p>Thanks in advance!</p>