dongyi9330 2014-06-18 13:06 采纳率: 100%
浏览 32
已采纳

symfony route无法匹配自己生成的uri

I define a route using the Symfony Routing Component

Using this route i generate an uri. 'https://domain.tl/login'

Upon navigating to that uri, the UrlMatcher fails to match and throws.

// $_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');
}

I really struggle figuring out how to debug this without diving in the Routing Component code. Hope i am missing something obvious :)

edit: The route does work without the restriction on https. This restriction is needed though.

edit2: it works! i implemented the fix in the code above

  • 写回答

1条回答 默认 最新

  • doukun1450 2014-06-18 13:12
    关注

    Yep, the problem you sad only on https, but if you check the value for the HTTP_HOST that don't say it's a http or https. I'm sure, it will work without the https restriction

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog