我有使用我的附加包的項目。這個包連接到其他數據庫,我需要配置另一個數據庫。Symfony2 - 包中的學說連接配置
我想在2個配置文件中有這個連接。
主要配置:
# ROOT/app/config/config.yml:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
捆綁配置:
# src/SecondBundle/Resources/config/config.yml
doctrine:
dbal:
connections:
secondBundle:
driver: "%secondBundle.database_driver%"
host: "%secondBundle.database_host%"
port: "%secondBundle.database_port%"
dbname: "%secondBundle.database_name%"
user: "%secondBundle.database_user%"
password: "%secondBundle.database_password%"
charset: UTF8
捆綁擴展文件:
class SecondBundleExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('config.yml');
}
}
在我看來一切正常,但是當我試圖運行這我有溝通:
There is no extension able to load the configuration for "doctrine"
看來您的包的配置正在讀取並在配置Doctrine之前運行。我建議你看看[CompilerPasses](http://symfony.com/doc/current/cookbook/service_container/compiler_passes.html)來相應地設置容器和配置優先級。 – hasumedic