【问题标题】:Import yml config in symfony2 config.yml file在 symfony2 config.yml 文件中导入 yml 配置
【发布时间】:2012-04-30 18:49:00
【问题描述】:

在我的 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"

我的导入有什么问题?

【问题讨论】:

  • 没什么,但看起来应该读取“sso_accounts”的 Bundle 没有正确加载。也许您忘记在您的 AppKernel 中加载它?

标签: symfony yaml


【解决方案1】:

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

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

【讨论】:

  • 对。不知道那件事。谢谢!
【解决方案2】:

如果您不使用捆绑包(因此它没有注册,并且@MyBundleName/Resources 无法访问......)您也可以这样做

//config.yml

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

【讨论】:

    【解决方案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 还很陌生,所以我不知道这是否是一个好方法。

    【讨论】:

      【解决方案4】:

      不是对 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');
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2013-12-22
        • 2014-04-24
        • 1970-01-01
        • 2013-07-11
        • 2011-06-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多