2013-07-26 70 views
2

我已經配置這兩條路線配置Silex的路線可選參數

$app->match ('/controller/param/{country}/{q}', "demo.controller:demoAction")->value ('country', 'de')->value('q', '')->bind ('demo_action_with_country'); 
$app->match ('/controller/param/{q}', "demo.controller:demoAction")->value ('q', '')->bind ('demo_action_without_country'); 

但是 - 這是行不通的。如果我撥打/controller/param/Test-String,則路線匹配並返回內容。如果我打電話/controller/param/DE/Test-String我得到NotFoundHttpException

我該如何解決問題?

回答

6

好的,我可以很容易地解決我自己的問題。這裏是我的解決方案:

$app->match ('/controller/param/{q}', "demo.controller:demoAction")->value ('q', false)->bind ('demo_action_without_country'); 
$app->match ('/controller/param/{country}/{q}', "demo.controller:demoAction")->value ('country', false)->value('q', '')->bind ('demo_action_with_country');