Symfony2索引路由2个参数
问题描述:
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 /"
我想要这个网址: p>
example.com \ nexample.com/category
example.com/category/name
nn我的路线: p>
default_page:\ n path:/ {name}
defaults:{_ control:CatalogWebBundle:Default:index}
default_page:
path:/
defaults:{_ control:CatalogWebBundle:Default:index}
default_page:
path:/ { name} / {category}
默认值:{_ control:CatalogWebBundle:默认值:index}
code> pre>
仅适用于 p>
example.com/category
code> pre>
我的路线出了什么问题? p>
错误是: p>
找不到“GET / category / name”的路由
找不到“GET /”
code> pre>
div>的路由
答
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 }
答
braces are for variables. When you type .com/category it will go into your first route with "category" as value of the variable name