Cakephp 2 несколько БД

Я хочу переключить БД на основе домена, выбрав учетные данные из другого БД, но я не могу переключиться ..

AppController.php

// Select username, password and database based on domain $this->Company->find('first', [...]); if ($company) { // Connect to second database, droping connection from first. $dataSource = ConnectionManager::getDataSource('default'); $dataSource->config['login'] = $company['Company']['dbuser']; $dataSource->config['password'] = $company['Company']['dbpass']; $dataSource->config['database'] = $company['Company']['dbname']; /** * PROBLEM START HERE: * Here, need to use new database settings, and, this case * Company table does not exists, but I always get it, so, * I think I am connected with the first and not second connection. */ print_r($this->Company->find('first')); } 

Как я могу это исправить?

РЕДАКТИРОВАТЬ

Я пробовал без успеха:

 ConnectionManager::drop('default'); ConnectionManager::create('default', $settings); по ConnectionManager::drop('default'); ConnectionManager::create('default', $settings); 

A print_r(ConnectionManager::create('default', $settings)) return:

 [... lots of things ... ] [config] => Array ( [persistent] => [host] => localhost [login] => login [password] => password [database] => database [port] => 3306 [datasource] => Database/Mysql [prefix] => ) [... more things ... ] 

EDIT 2

Теперь я могу переключать базу данных, но в модели компании всегда появляются старые настройки базы данных.

FooController.php

 <?php App::uses('AppController', 'Controller'); class FooController extends AppController { var $uses = array('Foo', 'Company'); public function index() { echo'<pre>'; print_r($this->Company->find('first')); // Here I get from old settings print_r($this->Foo->find('first')); // Here I gete from new settings echo'</pre>'; $this->layout = false; $this->render(false); } } 

AppController.php

 public function beforeFilter() { $company = ClassRegistry::init('Company')->find('first'); $settings = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => $company['Company']['dbuser'], 'password' => $company['Company']['dbpass'], 'database' => $company['Company']['dbname'], 'prefix' => '' ); ConnectionManager::getDataSource('default')->disconnect(); ConnectionManager::drop('default'); ConnectionManager::create('default', $settings); ConnectionManager::getDataSource('default')->connect(); } по public function beforeFilter() { $company = ClassRegistry::init('Company')->find('first'); $settings = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => $company['Company']['dbuser'], 'password' => $company['Company']['dbpass'], 'database' => $company['Company']['dbname'], 'prefix' => '' ); ConnectionManager::getDataSource('default')->disconnect(); ConnectionManager::drop('default'); ConnectionManager::create('default', $settings); ConnectionManager::getDataSource('default')->connect(); } по public function beforeFilter() { $company = ClassRegistry::init('Company')->find('first'); $settings = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => $company['Company']['dbuser'], 'password' => $company['Company']['dbpass'], 'database' => $company['Company']['dbname'], 'prefix' => '' ); ConnectionManager::getDataSource('default')->disconnect(); ConnectionManager::drop('default'); ConnectionManager::create('default', $settings); ConnectionManager::getDataSource('default')->connect(); } по public function beforeFilter() { $company = ClassRegistry::init('Company')->find('first'); $settings = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => $company['Company']['dbuser'], 'password' => $company['Company']['dbpass'], 'database' => $company['Company']['dbname'], 'prefix' => '' ); ConnectionManager::getDataSource('default')->disconnect(); ConnectionManager::drop('default'); ConnectionManager::create('default', $settings); ConnectionManager::getDataSource('default')->connect(); }