-1

我正在尝试学习 symfony2,但路由让我感到困惑

我已经成功地生成了捆绑包和带有动作的控制器

我想在同一个地方管理我的所有路由,而不是将每个路由模式放在每个 *bundle/resource/config/routing.yml

所以我像这样设置我的app/config/routing.yml

路由.yml

backend:
    resource: routing_backend.yml
    prefix: /admin

frontend:
    resource: routing_frontend.yml
    prefix: /

然后当我浏览 localhost/ 时就可以了,但是在 localhost/admin 出现错误

No route found for "GET /admin"

但是当我像这样重新排序routing.yml配置时

路由.yml

frontend:
    resource: routing_frontend.yml
    prefix: /

backend:
    resource: routing_backend.yml
    prefix: /admin

然后当我浏览 localhost/admin 但在 localhost/ 出错时就可以了

No route found for "GET /"

路由前端.yml

index:
    path: /
    defaults: { _controller: vRonnPageBundle:Page:index }

路由后端.yml

index:
    path: /
    defaults: { _controller: vRonnAdminPageBundle:Page:index }
4

1 回答 1

2

最后,在我使用命令php app/console router:debug检查所有可用路由后我知道了,并且只有一个路由名称索引,路由名称必须是唯一的,否则将被替换

路由前端.yml

frontend_index:
    path: /
    defaults: { _controller: vRonnPageBundle:Page:index }

路由后端.yml

backend_index:
    path: /
    defaults: { _controller: vRonnAdminPageBundle:Page:index }
于 2014-12-15T11:47:40.390 回答