0

特定の状況で、私の Symfony2 プロジェクトには異なるバージョンの構成ファイルがあります。具体的な単純な例は、セキュリティ ファイルです。

security_db.yml
security_ldap.yml

使用したファイルをファイルに定義してほしいparameters.ini。これは私が追加しようとしたものですconfig.yml

imports:
- { resource: "security_%authentification%.yml" }

authentificationファイルでパラメーターを定義している間、parameters.ini常に同じエラーが発生します:

The file "security_%authentification%.yml" does not exist
4

1 に答える 1

1

これを行う1つの方法は、Extensionクラスを使用して、parameters.iniで定義されている内容に基づいて適切な構成をロードすることです...これはテストされていません...

src / MyAwesomeBundle / DependencyInjection / MyAwesomeExtension.php

class MyAwesomeExtension extends Extension 
{

    public function load(array $configs, ContainerBuilder $container)
    {
       // boiler plate code here ... this probably already exists in your class.
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.xml');

        // your personalized loader goes here ...
        $myloader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));

        $auth = $container->getParameter('authentication');
        if (isset($auth)) {
            $myloader->load('security_' . $auth . '.yml');
        }
    }

}
于 2012-12-10T14:10:13.077 に答える