Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php symfony路由无法匹配其自己生成的uri_Php_Symfony_Reverse_Routes - Fatal编程技术网

Php symfony路由无法匹配其自己生成的uri

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

我使用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:
$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分钟规则,无法编辑我以前的评论。编辑评论时,我理解你的意思,并对其进行了测试。现在可以了!