Klaus S.
Klaus S.

Reputation: 1219

Silex Routing, how to have slashes inside route variables?

Take this URL, for example:

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

In Silex, it could be expressed as a route like this (just sample code):

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

However, this does not work as expected. Does anyone have any ideas on how to get this working?

Upvotes: 3

Views: 3098

Answers (2)

Steely Wing
Steely Wing

Reputation: 17597

Use this, .+ will match all remain path

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

Upvotes: 2

Lhassan Baazzi
Lhassan Baazzi

Reputation: 1150

try this:

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

for more, look at this cookbook: http://symfony.com/doc/current/cookbook/routing/slash_in_parameter.html

Upvotes: 3

Related Questions