I’m coming to Yii from CakePhp and one thing I think CakePhp did that is better than the way Yii handles things it is the datasource. I read that Yii has a hardcoded datasource of: Yii::app()->db which then reads the components array in protected/config/main.php to get the datasource connection strings. In CakePHP, however, there is a DATABASE_CONFIG class that has instance variables one for each datasource you would like to use in the app.
In addition to this class the cake bake scaffolding code would prompt you to select the datasource to use to generate the CRUD files. This makes it so much easier to set up a complex app that has multiple datasources.
I would suggest either a similar database_config class, or some additional array to tell Yii/Gii what entries are datasources.
'components'=>array( 'user'=>array( // enable cookie-based authentication 'allowAutoLogin'=>true, ), // ... 'datasources'=>array( //MySQL database //keep db as default datasource. 'db'=>array( 'connectionString' => 'mysql:host=MyDefaultHost;dbname=MyDefaultDatabase', 'emulatePrepare' => true, 'username' => 'MyDefaultUser', 'password' => 'MyDefaultPassword', 'charset' => 'UTF8', ), //MSSQL database 'kenny_db'=>array( 'connectionString' => 'mssql:host=myHost;dbname=mySchema', 'emulatePrepare' => true, 'username' => 'MyUser', 'password' => 'MyPassword', 'charset' => 'UTF8', 'class' => 'CDbConnection' ), //... additional datasources ) );
By doing this Gii can first give the option to choose a non-default datasource to use to generate the chosen files. Including adding the protected/componetns files to extend CActiveRecord.