Routing 使用可选参数配置Silex路由

Routing 使用可选参数配置Silex路由,routing,silex,Routing,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:demoAc

我已经配置了这两条路由

$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


我怎样才能解决这个问题呢?

好的,我可以自己轻松解决这个问题。以下是我的解决方案:

$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' );