0
我想以兩種方式調用一個函數(一組參數)。一個網址可以取兩組參數?? (過載模擬)symfony2
像
http://exampke.com/test/modea/2017/08/19
http://example.com/test/modeb/tomato
如果模式日期值是參數,
如果在模式B蔬菜名稱爲參數。
我該如何編寫這個route.yml和controller?
現在我只能採取蔬菜參數。
在route.ymlacme_member_myfunc:
path: /test/{mode}/{vegetable}
defaults: { _controller: AcmeMemberBundle:Default:myfuncAction }
在myController.php
public function myfuncAction($mode,$vegetable){
}
爲什麼你不寫2條路線?我的意思是會有一些'if'來檢查模式,然後根據模式做不同的事情,看起來像在這裏有2條路由更好的選擇 – kunicmarko20
因爲我想從一個像'url: {{path('acme_member_myfunc')}}' – whitebear
但你不能只是做'{{path('acme_member_myfunc')}}'你仍然需要檢查'value'是什麼,並基於你應該通過該模式。我會選擇2條路線並創建一個樹枝宏或樹枝函數,它將根據您的價值返回路線。 – kunicmarko20