Import yml configuration in symfony2 config.yml file

In my config.yml Symfony2 file, I would like to import some configs, which I would prefer to collect in a separate yml file.

I used:

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

And in my sso_accounts.yml file, I basically have:

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

But (there is always a but ...) I got this error:

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"

What happened to my import?

+3
source share
4 answers

The configuration from config.yml is loaded by extensions. Do you have one for your sso_accounts? It seems that you did not.

You can read how it works here: http://symfony.com/doc/current/cookbook/bundles/extension.html

+4
source

If the answer above does not work, try this (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, , .

+3

If you are not working with a package (and therefore have not registered it and cannot access @ MyBundleName / Resources ....), you can also do

//config.yml

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

+3
source

Not a direct response to OP. But here is another simple option that will help manage your configs inside the package:

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

All Articles