Добавляем новый компонент подключения в конфиге:
Код: Выделить всё
'components' => array(
....
'db_slave' => array(
...
),
),
Код: Выделить всё
class CommonModel extends CActiveRecord {
public function setDbConnection($name){
parent::$db = Yii::app()->getComponent($name);
}
protected function beforeDelete() {
$this->setDbConnection('db');
return parent::beforeDelete();
}
protected function beforeSave() {
$this->setDbConnection('db');
return parent::beforeSave();
}
protected function beforeFind() {
$this->setDbConnection('db_slave');
parent::beforeFind();
}
Все что не участвует в отображении информации на открываемой странице можно перенести после
Код: Выделить всё
$this->render('page');