title: MY_Model - dynamically change table?
body: <p>Using <a href="https://github.com/jamierumbelow/codeigniter-base-model" rel="nofollow">https://github.com/jamierumbelow/codeigniter-base-model</a>, how can I dynamicaly chnage the table name used in a model?</p>
  
  <p>I have some models that are very similar, one set used by users in Group A and the others by users in Group B.</p>
  
  <p>To save some coding and to make things neater, I'd like to consolidate the models, and would therefore need to pass along the group, and change the table depending on the group passed.</p>
  
  <p>I know I can set the table name underneath the start of the model class, but I'm wondering how I can set it dynamically any time a model method is called?</p>
  
  <p>Here is some test code I have:</p>
  
  <pre><code>function setGroup($group)
  {
      switch($group) {
          case 'admin':
          case 'mod':
              $this-&gt;table = 'library_categories';
              break;
          case 'members':
              $this-&gt;table = 'user_categories';
              break;
      }
  
      return $this;
  }
  </code></pre>
  
  <p>This doesn't work.</p>
  
  <p>If I name the model after the table for Group A, e.g. group_a_model.php, then even setting the table for Group B ($this->table = 'group_b') doesnt actually change the table for the query.</p>
  
  <p>I tried giving the model a generic name (group_model) but then I have to set "public $table = 'group_a')" in the model. Again, the code provided won't actually change the table used, it always uses table group_a...</p>
  
  <p>Is there a way to change the table used, using this MY_Model helper?</p>