我对Symfony路由有个问题。尽管我在两个不同路由的路径中使用了不同的参数,Symfony将其标识为一个模式,并将其定向到路由文件中首先定义的路径。对于ex:
app_restaurants_inner:
path: /london-restaurants/{id}/{restaurant_name}.html
defaults: { _controller: AppBundle:Restaurants:inner}
app_restaurants_by_cuisine:
path: /london-restaurants/cuisine/{cuisine}.html
defaults: { _controller: AppBundle:Restaurants:index}第一个路由加载一个特定的餐厅,参数是id和餐厅名称。餐厅名称仅包含a-z、0-9和连字符。在第二个参数中,只有一个参数,即菜肴。但是当我尝试加载一个菜肴(第二条路线)时,它会将我引导到餐厅路径,它有一个与菜肴相似的路径。
另一方面,下面的路线也被确定为类似于餐厅的路线。
app_restaurants_by_cuisine_letter:
path: /london-restaurants/cuisine/{cuisine}-{letter}.html
defaults: { _controller: AppBundle:Restaurants:index}单词'cuisine‘被标识为'{id}’,而'{cuisine}-{letter}‘被标识为'{restaurant_name}’。
我该如何解决这个问题呢?
发布于 2019-05-07 14:19:28
您应该在路由定义Adding {wildcard} Requirements中添加一些要求
app_restaurants_inner:
path: /london-restaurants/{id}/{restaurant_name}.html
defaults: { _controller: AppBundle:Restaurants:inner}
requirements:
id: '\d+'
app_restaurants_by_cuisine:
path: /london-restaurants/cuisine/{cuisine}.html
defaults: { _controller: AppBundle:Restaurants:index}https://stackoverflow.com/questions/56016429
复制相似问题