2012-08-16 131 views
3

拿这个URL,例如: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-._/]+'); 

然而,这并不能作为工作预期。有没有人有任何想法如何让这个工作?

+0

预期“,你的意思是你正在得到一个404错误或究竟是什么? – 2012-08-16 05:40:41

+0

您需要在* both *分支和树参数中使用斜线。在这里你只允许他们在分支。 – AdrienBrault 2012-08-16 07:42:32

回答

2

使用此,.+将匹配当你说“不为所有工作留路径

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