在symfony2 config.yml文件中导入yml config

时间:2012-04-19 09:11:10

标签: symfony yaml

在我的Symfony2 config.yml文件中,我想导入一些我更喜欢在一个单独的yml文件中收集的配置。

我用过:

imports:
- { resource: parameters.yml }
- { resource: sso_accounts.yml }

在我的sso_accounts.yml文件中,我基本上有:

sso_accounts:
  company:
    publickey:  publickey
    secret:     privatekey
    users:      [ user1@email.com, user2@email.com ]

但是(总有一个但是......)我收到了这个错误:

Whoops, looks like something went wrong.

2/2 FileLoaderLoadException: Cannot import resource "/Users/mycomp/Sites/myapp/app/config/sso_accounts.yml" from "/Users/mycomp/Sites/myapp/app/config/config.yml".

1/2 InvalidArgumentException: There is no extension able to load the configuration for "sso_accounts" (in /Users/mycomp/Sites/myapp/app/config/sso_accounts.yml). Looked for namespace "sso_accounts", found "framework", "security", "twig", "monolog", "swiftmailer", "doctrine", "assetic", "sensio_framework_extra", "jms_security_extra", "problematic_acl_manager", "twig_js", "fos_js_routing"

我的导入有什么问题?

4 个答案:

答案 0 :(得分:4)

config.yml的配置由扩展加载。你有一个sso_accounts吗?好像你没有。

您可以在这里阅读它的工作原理: http://symfony.com/doc/current/cookbook/bundles/extension.html

答案 1 :(得分:3)

如果以上答案不起作用,试试这个(Symfony 2.3.4):

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

然后,配置文件必须位于src / Folder / YourBundleName / Resources / config / config.yml

我是Smyfony2的新手,所以我不知道这是不是一个好方法。

答案 2 :(得分:3)

如果您不使用捆绑包(因此未注册,并且无法通过@ MyBundleName / Resources ....访问),您也可以

// config.yml

- { resource: '../../src/Some/Where/Configuration/settings.yml' }

答案 3 :(得分:0)

不是OP的直接答案。但是,这是另一个简单的选项,可以帮助管理你的配置:

namespace Acme\DemoBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
 * This is the class that loads and manages your bundle configuration
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
 */
class AcmeDemoExtension extends Extension
{
    /**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
        $loader->load('otherstuff.yml');
        $loader->load('stillotherstuff.yml');
    }
}