亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Symfony 路由以區分不明確的路徑

Symfony 路由以區分不明確的路徑

PHP
慕容3067478 2021-06-03 07:10:32
我有 Symfony 路由問題。即使我在兩個不同路由的路徑中使用了不同的參數,Symfony 也將其識別為一個模式并指向路由文件中首先定義的路徑。例如: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 和餐廳名稱。餐廳名稱僅包含 az、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}”。我怎樣才能解決這個問題?
查看完整描述

1 回答

?
ibeautiful

TA貢獻1993條經驗 獲得超6個贊

您應該在路由定義中添加一些要求

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}


查看完整回答
反對 回復 2021-06-04
  • 1 回答
  • 0 關注
  • 215 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號