Silex Routing,如何在路由变量中包含斜杠?

时间:2012-08-16 05:34:27

标签: php silex

获取此网址,例如:

http://website.com/test/blob/my/nice/little/branch/tests/InterfaceTest.php

在Silex中,它可以表示为这样的路线(只是示例代码):

$app->get('{repo}/blob/{branch}/{tree}/', function($repo, $branch, $tree) use ($app) {
    // repo = test
    // branch = my/nice/little/branch
    // tree = tests/InterfaceTest.php
})->assert('branch', '[\w-._/]+');

但是,这不能按预期工作。有没有人对如何使这个工作有任何想法?

2 个答案:

答案 0 :(得分:3)

试试这个:

$app->get('{repo}/blob/{branch}/{tree}/', function($repo, $branch, $tree) use ($app) {
     // repo = test
     // branch = my/nice/little/branch
     // tree = tests/InterfaceTest.php

})->assert('branch', '[\w\-\._/]+');

了解更多信息,请查看此食谱:http://symfony.com/doc/current/cookbook/routing/slash_in_parameter.html

答案 1 :(得分:2)

使用此功能,.+将匹配所有剩余路径

$app->get('{repo}/blob/{branch}/{tree}', function($repo, $branch, $tree) {
    return "$repo, $branch, $tree";
})->assert('branch', '.+');