简体   繁体   中英

Symfony2 index routes 2 parameters

I want have this urls:

example.com
example.com/category
example.com/category/name

My routes:

default_page:
    path:     /{name}
    defaults: { _controller: CatalogWebBundle:Default:index }
default_page:
    path:     /
    defaults: { _controller: CatalogWebBundle:Default:index }
default_page:
    path:     /{name}/{category}
    defaults: { _controller: CatalogWebBundle:Default:index }

Work properly only

example.com/category

What is wrong with my routes ?

Error is:

No route found for "GET /category/name"
No route found for "GET /"

braces are for variables. When you type .com/category it will go into your first route with "category" as value of the variable name

make your internal name of the route unique and it should work properly.

default_page_X:
    path:     /{name}
    defaults: { _controller: CatalogWebBundle:Default:index }
default_page_Y:
    path:     /
    defaults: { _controller: CatalogWebBundle:Default:index }
default_page_Z:
    path:     /{name}/{category}
    defaults: { _controller: CatalogWebBundle:Default:index }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM