dongyushen9063
2013-07-13 06:39 阅读 55
已采纳

Symfony2没有获取多个路由yml文件/导入无法在yml文件中工作

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douchen7555 douchen7555 2013-07-13 08:24

    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.

    点赞 评论 复制链接分享

相关推荐