3

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

4 回答 4

4

来自 config.yml 的配置由扩展加载。您的 sso_accounts 有一个吗?看来你没有。

你可以在这里阅读它是如何工作的:http: //symfony.com/doc/current/cookbook/bundles/extension.html

于 2012-04-19T09:32:54.360 回答
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 相当陌生,所以我不知道这是否是一个好方法。

于 2014-01-13T20:58:26.307 回答
3

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

//config.yml

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

于 2014-07-30T08:38:08.063 回答
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');
    }
}
于 2014-11-06T22:11:20.950 回答