Search code examples
phpsymfonysymfony-2.6

Symfony2 routing.yml setting routing_frontend.yml and routing_backend.yml in same directory


im trying to learn symfony2, but the routing make me confuse

i have successfully generate both of the bundle and also controller with action

i wanna manage all my routing in same place other than putting each routing pattern in each *bundle/resource/config/routing.yml

so i set my app/config/routing.yml like this

routing.yml

backend:
    resource: routing_backend.yml
    prefix: /admin

frontend:
    resource: routing_frontend.yml
    prefix: /

then is ok when i surf localhost/ , but error at localhost/admin

No route found for "GET /admin"

but when i reorder the routing.yml config like this

routing.yml

frontend:
    resource: routing_frontend.yml
    prefix: /

backend:
    resource: routing_backend.yml
    prefix: /admin

then is ok when i surf localhost/admin but error at localhost/

No route found for "GET /"

routing_frontend.yml

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

routing_backend.yml

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

Solution

  • Finally i know it after i check all the available route with command php app/console router:debug and there is only one route name index, the route name must be unique or will replaced

    routing_frontend.yml

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

    routing_backend.yml

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