【问题标题】:Configure Silex Routes with optional parameters使用可选参数配置 Silex 路由
【发布时间】:2013-07-26 12:35:29
【问题描述】:

我已经配置了这两条路线

$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

我该如何解决这个问题?

【问题讨论】:

    标签: routing silex


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-18
      • 1970-01-01
      • 2015-12-07
      • 1970-01-01
      • 2019-05-04
      • 2012-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多