3
votes

I'm trying to create a folder structure like described in Different Directories per Environment:

- app
    - config
        - common
            - config.yml
            - routing.yml
        - dev
            - config.yml
            - routing.yml

This does work pretty well for all files (config.yml, parameters.yml etc.) but nor for config.yml.

I get this error:

The routing file "[…]" contains unsupported keys for "imports": "0". Expected one of: "resource", "type", "prefix", "pattern", "path", "host", "schemes", "methods", "defaults", "requirements", "options", "condition".

What I've done so far:

appKernel.php

public function registerContainerConfiguration(LoaderInterface $loader) {
    $loader->load($this->getRootDir().'/config/'.$this->getEnvironment().'/config.yml');
}

routing.yml in dev

#app/config/dev/routing.yml
imports:
    - { resource: ../common/routing.yml }

config.yml in common

#app/config/common/config.yml
imports:
    - { resource: 'parameters.yml' }
    - { resource: 'security.yml' }
    - { resource: 'services.yml' }

framework:
    router:
        resource: "%kernel.root_dir%/config/common/routing.yml"

config.yml in dev

#app/config/dev/config.yml
imports:
    - { resource: '../common/config.yml' }
    - { resource: 'parameters.yml' }
    - { resource: 'security.yml' }
    - { resource: 'services.yml' }

framework:
    router:
        resource: "%kernel.root_dir%/config/dev/routing.yml"

What did I miss here?

1
did you change the code of the registerContainerConfiguration() method ?Freelancer
@Freelancer Yes, I did. I've added the code to the question.lampshade
in your config.yml why are you not importing the parameters.yml and security.yml ?Freelancer
@Freelancer Actually I do. I just removed it to make the question shorter - I've added the whole thing now.lampshade
why not calling directly routing.yml from common in your app/config/dev/config.yml instead of creating a routing.yml that import the file from common ?Freelancer

1 Answers

6
votes

Finally I got it running. I have set the new routing file in my dev config:

#app/config/dev/config.yml
framework:
    # update routing
    router:
        resource: "%kernel.root_dir%/config/dev/routing.yml"

And I imported the common routing in the dev routing by not using imports: - { resource: ../common/routing.yml } but this instead:

#app/config/dev/routing.yml
_common:
    resource: ../common/routing.yml

Works like a charm. It seems that the import directive is not allowed in the routing.yml.