Symfony2-捆绑中的学说连接配置 [英] Symfony2 - doctrine connection configuration in bundle

查看:43
本文介绍了Symfony2-捆绑中的学说连接配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用附加捆绑包的项目。此捆绑包连接到其他数据库,我需要为另一个数据库进行配置。

I have project which uses my additional bundle. This bundle connects to other database and I need configuration for another database.

我希望将此连接包含在2个配置文件中。

I want to have this connections in 2 config files.

主配置:

# 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');
    }
}

我认为一切都很好,但是当我在尝试运行此命令时,我已经进行了交流:

In my opinion everything looks OK, but when I'm trying to run this I have communicate:


没有扩展能够加载 doctrine的配置

There is no extension able to load the configuration for "doctrine"


推荐答案

您可以将额外的配置添加到 app / config / config中的导入中。 yml ,以便将其合并到完整的 config 中。

You can add your extra config to the imports in your app/config/config.yml so that it is merged into the full config.

app /config/config.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: '@SecondBundle/Resources/config/config.yml' }

由于以下事实而用引号更新:未引用的字符串不能以@或`(保留)或标量指示符(|或>)开头从3.0版开始。

Updated with quotes due to the fact that a non-quoted string cannot start with @ or ` (reserved) nor with a scalar indicator (| or >) since version 3.0.

这篇关于Symfony2-捆绑中的学说连接配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆