3

たとえば、次の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-._/]+');

ただし、これは期待どおりに機能しません。誰かがこれを機能させる方法について何かアイデアがありますか?

4

2 に答える 2

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

于 2012-08-16T12:00:37.803 に答える
2

これを使用すると、.+すべての残りのパスに一致します

$app->get('{repo}/blob/{branch}/{tree}', function($repo, $branch, $tree) {
    return "$repo, $branch, $tree";
})->assert('branch', '.+');
于 2014-02-28T13:20:48.283 に答える