title: Yii model overriding based on constant
body: <p>I need to change model class in my yii2 project. Because of a change in database so all the query of model class need to be converted according
  to new database table. But I want to the old db configuration also because if something went wrong in my new db then i can easily move to all
  model class query (failover). So i want a old model class and override it with new model class function based on constant. In constant if i'm set 
  old (0) then pick the old db class query or new (1) then override the model with new query. How this is possible using OOPS concept please 
  help .</p>
  
  <pre><code>class ModelClass extends ActiveRecord
  {
      public static function tableName()
      {
          return 'table1';
      }
      public function getData($limit = '5', $offset = '0')
      {
       //
      }
  }
  </code></pre>
  
  <p>New Model class.</p>
  
  <pre><code>class NewModelClass extends ModelClass
  {
      public static function tableName()
      {
          return 'table2';
      }
      public static function getDb()
      {
          return \Yii::$app-&gt;get('newDb'); // second database
      }
      public function getData($limit = '5', $offset = '0')
      {
       //
      }
  }
  </code></pre>
  
  <p>In Controller class i'm using the parent model class in namespace like :</p>
  
  <pre><code>use api\modules\v1\models\ModelClass;
  </code></pre>
  
  <p>For calling function of model in action : </p>
  
  <pre><code>$objModel = new ModelClass(); // call parent class 
  $objModel-&gt;getData();
  </code></pre>
  
  <p>Define constant in params:</p>
  
  <pre><code>'model' =&gt; '1', // 1 means new or 0 means old
  </code></pre>
  
  <p>Then how to switch between model without putting if else conditions in everywhere of controller . Need a basic check 0/1 to switch between the classes of model.</p>