【问题标题】:Kohana routing does not match optional paramKohana 路由与可选参数不匹配
【发布时间】:2013-05-10 14:02:51
【问题描述】:

最后我无法获得带有可选参数的路由来解析 ID。这是我的路线:

Route::set('default', '<action>(/<id>)', array(
    'action' => '.*',
    'id' => '\d+'
))->defaults(array(
    'controller' => 'MediaLibrary',
    'action' => 'index'
));

当我查看参数时,我得到:

array(2) (
    "action" => string(7) "test/91"
    "controller" => string(12) "MediaLibrary"
)

但是,如果我将路线更改为&lt;action&gt;/(&lt;id&gt;),它会起作用。 id 将毫无问题地被解析并且操作将更改为test 而不是test/91

【问题讨论】:

    标签: php routing routes kohana kohana-3


    【解决方案1】:

    它不起作用,因为action 参数有包罗万象的正则表达式,请尝试将其更改为[a-z0-9]+

    Route::set('default', '<action>(/<id>)',
        array(
            'action' => '[a-z0-9]+',
            'id'     => '\d+'
        ))
        ->defaults(array(
            'controller' => 'MediaLibrary',
            'action'     => 'index'
        ));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-27
      • 1970-01-01
      • 1970-01-01
      • 2013-11-26
      • 2012-03-31
      • 1970-01-01
      相关资源
      最近更新 更多