dongyushen9063 2013-07-13 06:39
浏览 60
已采纳

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 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘