获取此网址,例如:
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-._/]+');
但是,这不能按预期工作。有没有人对如何使这个工作有任何想法?
答案 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', '.+');