I’m using Yii 1.1.13. I had the need to connect to different databases so I have certain models which extend a class that overrides the CActiveRecord
For example, my news model:
class Noticias extends DBNoticiasActiveRecord
{
//override default db conn
public function getDbConnection()
{
return self::getBDNoticiasDbConnection();
}
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Noticias the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'TblNoticias';
}
...
And my DBNoticiasActiveRecord class is:
/**
* Custom wrapper class to CActiveRecord.
* getBDNoticiasDbConnection() override Controller. All News controller classes for this application should extend from this class.
*/
class DBNoticiasActiveRecord extends CActiveRecord {
private static $dbnoticias = null;
protected static function getBDNoticiasDbConnection()
{
if (self::$dbnoticias !== null)
return self::$dbnoticias;
else
{
self::$dbnoticias = Yii::app()->dbnoticias;
if (self::$dbnoticias instanceof CDbConnection)
{
self::$dbnoticias->setActive(true);
return self::$dbnoticias;
}
else
throw new CDbException(Yii::t('yii','Active Record requires a "db" CDbConnection application component.'));
}
}
}
What I’m trying to do is apply an ajax filter form before the CListView in my view. I’ve got it working in other Yii apps where there is only 1 database connection. But with this override, the listview doesn’t get filtered.
Is there something elese I should be doing? I reaaly need this to work and it seemed so simple to implement.
Thanks,
Mário