We are going to deploy the new yiiframework.com website on March 23, 2018 from 8:00 to 12:00 UTC.
Website and Yii documentation will not be available in this time frame. Check the news for more details.

Difference between #2 and #1 of A simple class to use a different db for a module

A simple class to use a different db for a module
module, database, active record, tips
What would you do if you want/need to have a different than the main database
connection in an module's models?

##How to use
Let's say we create a module with name test under the
<code>protected/modules/</code> folder.

In your config file you can declare a module like:



__Important:__ The <code>'class'=>'CDbConnection'</code> is
required, for this simple implementation.

In your <code>TestModule.php</code> file ( the class that extends
the <code>CModule</code> ) under the
folder, declare a public property named db.

class TestModule extends CModule
  public function $db;

###Your models
Then you have to simple change the <code>CActiveRecord</code> class
your module's models extends to

class EModuleActiveRecord extends CActiveRecord
    public function getDbConnection()
        $db = Yii::app()->controller->module->db;
        return Yii::createComponent($db);

In this scenario we had a module that we wanted to change database for, but the
extension of the <code>CActiveRecord</code> and the 
override of the <code>getDdConnection()</code> is common general a
common case.
Make sure you import the <code>EModuleActiveRecord</code>. If you
have generated the module with gii, just add file under the
components or models folder.