문제

So first off TL:DR - Symfony isn't picking up additional routing files in my bundle. Don't know why. Tried doing imports like in config.yml and it's not working either

I have multiple controllers for maintainability of my code. I.e. All site related actions are in a SiteController, all app related actions are in an AppController, etc.

So I figured I'd make routing files to correspond with my controllers. The files are housed in MyBundle/Resources/config. The thing is they are not being picked up when i do a php app/console router:debug. So I thought, well I'll just import them into the routing_mybundle.yml file that symfony generated during the generate:bundle process. So I did the following:

imports:
    - { resource: routing_site.yml }
    - { resource: routing_app.yml }

I'm getting an error message that says:

routing_mybundle.yml contains unsupported keys for "import": "0", "1". Expected one of: "resource", "type", "prefix", "pattern", "path", "host", "schemes", "methods", "defaults", "requirements", "options".

I realize that it's looking for specific keys, but I'm not sure why it would work in the config.yml but not in a routing.yml file.

If I do the following it works:

imports:
    resource: routing_site.yml

Or if I "chain" the imports in the files it works. So by this I mean I import routing_app into routing_site and routing_site into routing_mybundle.

Anyone know how to get the imports tag to work, or how to make it so that symfony will pick up my routing_**.yml files?

Thanks :)

EDIT:

Thanks to forgottenbas for the answer. For those who had the same problem as me (multiple config files in the same bundle) here's what I had to do within the routing.yml file WITHIN myBundle/Resources/config.

My directory structure looks like

MyBundle/
    Resources/
        config/
            routing.yml
            routing_site.yml
            routing_app.yml

So I had to do the following

SiteController:
    resource: routing_site.yml

AppController:
    resource: routing_app.yml

Thanks Again

도움이 되었습니까?

해결책

You can import routing files this way

routing.yml

SiteBundle:
    resource: "@SiteBundle/Resources/config/routing_site.yml"

AppBundle:
    resource: "@AppBundle/Resources/config/routing_app.yml"

FOSUserBundle do it the same.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top