title: Yii: using a module specific database for access control
body: <p>I'm trying to set up a separate database for special set of users who will access my site through a Yii module, but I can't quite seem to get the configuration right. </p>
  
  <p>Here are the relevant files my module heirarchy.
  <pre><code>/protected/modules/special
  /protected/modules/special/SpecialModule.php
  /protected/modules/special/models/SpecialActiveRecord.php
  /protected/modules/special/models/Account.php
  /protected/modules/special/components/UserIdentity.php
  </pre></code></p>
  
  <p>Per instructions <a href="http://www.yiiframework.com/wiki/193/a-simple-class-to-use-a-different-db-for-a-module/" rel="nofollow">here</a>, I've updated my main.config to include a module specific database definition.</p>
  
  <pre><code>'modules'=>array(
      'special'=>array(
          'db'=>array(
              'connectionString'=>'mysql:dbname=specialdatabase',
              'username'=>'special',
              'password'=>'special',
          ),
      ),
  ),</code></pre>
  
  <p>I have also updated my module to support the database definition by adding <code>public $db</code> to SpecialModule.php and I have created a module specific active record that utilizes the database definition.</p>
  
  <p><pre><code>class SpecialActiveRecord extends CActiveRecord
  {
      public function getDbConnection()
      {
          $db = Yii::app()->controller->module->db;
          return Yii::createComponent($db);
      }
  }</pre></code></p>
  
  <p>Where I'm having trouble is in the account model.  My primary web application also implements an account model and the stack trace shows that the module is accessing all of my module specific files through user identity (<code>/protected/modules/special/components/UserIdentity.php</code>).  The account model that is being used for authorization, however, is referenced at the site level (<code>/protected/models/Account.php</code>).</p>
  
  <p>Any ideas on the proper way to implement module specific authentication using a module specific database?</p>