Referer Redirect 在 symfony 4 中的 POST 调用中使用 URL 和注释注释路由

Referer Redirect in a POST call in symfony 4 using URL with annotations comments Routes

在版本 symfony 4 中,我试图解决之前使用参数完成的操作中的重定向。我有注释路由。

问题是它是一个 POST 调用,我不知道如何将 URL $request->headers->get('referer') 转换为 action_name 或如何在调用中插入参数。

$op = 4; //This is an example of a number

$response = new RedirectResponse($request->headers->get('referer'),307,$headers=['op'=>$op]);
return $response;

$op = 4; //This is an example of a number    
$response = $this->redirect($request->headers->get('referer'));
return $response;

你知道解决这个问题的方法吗?

您可以注入 router 服务(RouterInterface 的实例)并使用其 matchmatchRequest 方法。

例如:

public function testAction(RouterInterface $router, Request $request) {
    $route = $router->matchRequest(Request::create($request->headers->get('referer')));

    return $this->redirectToRoute($route['_route'], ['op' => 4], 307);
}