function getDbConnection() { if (self::$db !== null) { return self::$db; } else { self::$db = Yii::app()->getDb(); if (self::$db instanceof CDbConnection) { return self::$db; } else { throw new CDbException(Yii::t('yii', 'Frontend Active Record requires a "frontendDb" CDbConnection application component.')); } } }