schmunk42 / gii-template-collection

Gii Template Collection with code templates for models and CRUDs
https://github.com/schmunk42/gii-template-collection
51 stars 20 forks source link

Property "FullModelCode.connectionId" is not defined. #73

Open derekisbusy opened 9 years ago

derekisbusy commented 9 years ago

You have to add...

    public $connectionId = 'db';

to the FullModelCode class.

uldisn commented 9 years ago

That mean need rewrite getDbConnection()?

derekisbusy commented 9 years ago

No. Just add it to the class declaration. This would correspond to the component in the main config...

'components'=>array(
        // ...
        'db'=>array(
            'connectionString' => 'mysql:host=localhost;dbname=yii',
            'emulatePrepare' => true,
            'username' => 'root',
            'password' => 'test',
        ),
                // second db connection...
        'db2'=>array(
            'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
        ),

Where the components key in the config array is the FullModelCode connectionId.

uldisn commented 9 years ago

In http://www.yiiframework.com/doc/api/1.1/CActiveRecord#getDbConnection-detail described: "You may override this method if you want to use a different database connection."

schmunk42 commented 9 years ago

@derekisbusy I also agree to @uldisn, you should implement the dbConnection in the model as described in the Yii guide. You can specify a base class in the model generator and set the connection there, so you have only one place where you'd have to add the configuration - you may also use values from the config.

Please let me know if this solves the issue for you.