title: Yii: How to refresh or unset or reset a model?
body: <p>I need to refresh, reset or unset a model;</p>
  
  <p>Normally, by using a <code>for</code> operation, the <code>public static $k</code> value should change, and id does change, but the <code>tableName</code> model method is called only once;</p>
  
  <p>the value of <code>tablename</code> will always be <code>1</code>, because that is the fisrt value of <code>$i</code>;</p>
  
  <pre><code>for($i=1;$i&lt;=100;$i++){
  VillageBuildingKXSlaveM::$server_id = 1;
  VillageBuildingKXSlaveM::$k = $i;
  VillageBuildingKXSlaveM::model()-&gt;findAllByAttributes(array());
  }
  
  &lt;?php
  
  class VillageBuildingKXSlaveM extends VillageBuildingKXM {
  
      public static function model($className = __CLASS__) {
          return parent::model($className);
      }
  
      public static $server_id;
      public static $slave_db;
      public static $k;
  
      public function getDbConnection() {
          self::$slave_db = Yii::app()-&gt;dbx;
          if (self::$slave_db instanceof CDbConnection) {
              self::$slave_db-&gt;active = false;
              $config = require(Yii::app()-&gt;getBasePath() . '/config/main.php');
              $connectionString = $config['components']['dbx']['connectionString'];
              self::$slave_db-&gt;connectionString = sprintf($connectionString, self::$server_id);
              self::$slave_db-&gt;setActive(true);
              return self::$slave_db;
          } else
              throw new CDbException(Yii::t('yii', 'Active Record requires a "db" CDbConnection application component.'));
      }
  
      public function tableName() {
          return 'village_building_k' . self::$k;
      }
  
  }
  </code></pre>