Php Silex路由,如何在路由变量中使用斜线?

Php Silex路由,如何在路由变量中使用斜线?,php,silex,Php,Silex,以这个URL为例: 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) { // re

以这个URL为例:

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\-\._/]+');

有关更多信息,请参阅本食谱:

使用此选项,
+
将匹配所有剩余路径

$app->get('{repo}/blob/{branch}/{tree}', function($repo, $branch, $tree) {
    return "$repo, $branch, $tree";
})->assert('branch', '.+');
当您说“不能按预期工作”时,您的意思是您得到了404错误还是什么?您需要在分支和树参数中都允许斜杠。在这里,您只允许在分支中使用它们。
$app->get('{repo}/blob/{branch}/{tree}', function($repo, $branch, $tree) {
    return "$repo, $branch, $tree";
})->assert('branch', '.+');