0

我无法获得带有可选参数的路由来最后解析 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"
)

但是,如果我将路线更改为<action>/(<id>)有效。将毫无问题地解析 ID,并且操作将更改为test而不是test/91

4

1 回答 1

0

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

Route::set('default', '<action>(/<id>)',
    array(
        'action' => '[a-z0-9]+',
        'id'     => '\d+'
    ))
    ->defaults(array(
        'controller' => 'MediaLibrary',
        'action'     => 'index'
    ));
于 2013-05-11T14:13:54.143 回答