gpt4 book ai didi

php - Silex Routing,如何在路由变量中添加斜线?

转载 作者:可可西里 更新时间:2023-11-01 00:48:43 26 4
gpt4 key购买 nike

以这个网址为例:

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) 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

关于php - Silex Routing,如何在路由变量中添加斜线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11981212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com