Extendedactiverecord inherit from Cactiverecord, so the basic function is no different from Cactiverecord
To add support for multiple database connections, a callback to the ConnectionName () method is added, and the usage is consistent with the existing TableName () method, which returns a string of database connection component names.
If the method is not defined, the default database connection (db) is used
The source code is as follows:
Class Extendedactiverecord extends cactiverecord{public static $db = Array (); /** * @return cdbconnection * @throws cdbexception * * Public function getdbconnection () { $ ComponentName = $this->connectionname (); if (Isset (self:: $db [$componentName])) { return self:: $db [$componentName]; } else {self :: $db [$ ComponentName] = Yii::app ()->getcomponent ($componentName); if (self:: $db [$componentName] instanceof Cdbconnection) return to self:: $db [$componentName]; else { $message = ' Active Record keyword requires a '. $componentName. ' cdbconnection application component. '; Yii::log ($message, Clogger::level_error, ' extended '); throw new CDBException (Yii::t (' Yii ', $message)); }}} Public Function ConnectionName () { return ' db '; }}
Instance:
Class Somemodelclass extends extendedactiverecord{... Public Function ConnectionName () { return ' some-db-connection '; } ......}