title: Class 'yii\app\models\DB' not found in yii2
body: <p>I am trying to use database connection inside my model but it was not getting connected throwing error as "Class 'app\models\DB' not found". I have created a common model to be extended by all my models inside modules that means all models extends the CommonModel, I am getting this error inside the CommonModel. I have read yii documentation regards database connection &amp; googled for the same but I din't find any solution. My code is:</p>
  
  <p>models\CommonModel.php</p>
  
  <pre><code>namespace app\models;
  use Yii;
  use yii\base\NotSupportedException;
  use yii\db\ActiveRecord;
  use yii\helpers\Security;
  use yii\web\IdentityInterface;
  use yii\db\Query;
  use app\models\Mailsettings;
  use \PDO as PDO;
  class CommonModel extends \yii\db\ActiveRecord{
    protected $_db;
    protected $_sql;
    public function __construct()
    {
      $this-&gt;_db = DB::init();  // This line causing the error
      $pdo = Timetrackdb::getPdoConnection(); 
    }
    ----
    ----
  }
  </code></pre>
  
  <p>config/db.php &amp; config/db2.php</p>
  
  <pre><code>return [
    'class' =&gt; 'yii\db\Connection',
    'dsn' =&gt; 'mysql:host=localhost;dbname=my_db_name',
    'username' =&gt; 'db_username',
    'password' =&gt; 'db_password',
    'charset' =&gt; 'utf8',
  ];
  </code></pre>
  
  <p>config/web.php</p>
  
  <pre><code>$db = require __DIR__ . '/db.php';
  $db2 = require __DIR__ . '/db2.php';
  $config = [
    'id' =&gt; 'basic',
    'basePath' =&gt; dirname(__DIR__),
    'bootstrap' =&gt; ['log'],
    'modules' =&gt; [
       'my_module1' =&gt; [
          'class' =&gt; 'app\modules\my_module1'
       ],
       'my_module2' =&gt; [
          'class' =&gt; 'app\modules\my_module2'
       ],
     ],
    ------
    ------
    'db' =&gt; $db,
    'db2' =&gt; $db2,
    ------
    ------
  ];
  </code></pre>
  
  <p>I have created 2 modules in which one module is working fine with the same type of database connection but the other module's db connection is not working properly. Can anyone please tell whats wrong with this code? Thanks.</p>