Php symfony路由无法匹配其自己生成的uri
我使用Symfony路由组件定义路由 使用此路由,我生成一个uri。”https://domain.tl/login" 导航到该uri时,UrlMatcher无法匹配并抛出Php symfony路由无法匹配其自己生成的uri,php,symfony,reverse,routes,Php,Symfony,Reverse,Routes,我使用Symfony路由组件定义路由 使用此路由,我生成一个uri。”https://domain.tl/login" 导航到该uri时,UrlMatcher无法匹配并抛出 // $_SERVER['REQUEST_URI'] == 'https://domain.tl/login' // old situation //$request_context = new RequestContext($_SERVER['REQUEST_URI']); // problem solved: $p
// $_SERVER['REQUEST_URI'] == 'https://domain.tl/login'
// old situation
//$request_context = new RequestContext($_SERVER['REQUEST_URI']);
// problem solved:
$protocol = $_SERVER['SERVER_PORT'] == 80 ? 'http':'https';
$request_context = new RequestContext($_SERVER['REQUEST_URI']);
$request_context->setScheme($protocol);
$routes = new RouteCollection;
// should match: https://domain.tl/login
$routes->add('login', new Route('login', array(), array(), array(), '', array('https')));
// reverse routing
$base_uri = new RequestContext;
$base_uri->setHost($_SERVER['HTTP_HOST']);
$generator = new UrlGenerator($routes, $base_uri);
var_dump($generator->generate('login')); // gives: https://domain.tl/login
try
{
$matcher = new UrlMatcher($routes, $request_context);
$matcher->match($_SERVER['REQUEST_URI']); // throws
die('match');
}
catch(\Symfony\Component\Routing\Exception\ResourceNotFoundException $ex)
{
die('no match');
}
我真的很难弄明白如何在不深入路由组件代码的情况下调试它。
希望我错过了一些明显的东西:
编辑:路由不受https的限制。不过,这种限制是必要的
edit2:真管用!我在上面的代码中实现了修复是的,您只会在https上遇到这个问题,但是如果您检查HTTP_主机的值,该主机不会说它是HTTP或https。我确信,它将在没有https限制的情况下工作是的,它在没有限制的情况下工作。但这不是我想要/需要的。由于5分钟规则,无法编辑我以前的评论。编辑评论时,我理解你的意思,并对其进行了测试。现在可以了!