如何在 symfony 中恢复页面的先前路由名称
how to recover a previous route name of page in symfony
例如我在主页上,它有路由名称"home",在我离开另一个页面后例如编辑,如何在编辑页面上获取上一个路由的名称(这里它是家)?谢谢
您可以获取引荐来源网址并尝试 "match" 它与路由服务一起查看是否存在此路径的路由:
$referer = $request->headers->get('referer'); // get the referer, it can be empty!
if (!\is_string($referer) || !$referer) {
echo 'Referer is invalid or empty.';
return;
}
$refererPathInfo = Request::create($referer)->getPathInfo();
// try to match the path with the application routing
$routeInfos = $this->router->match($refererPathInfo);
// get the Symfony route name if it exists
$refererRoute = $routeInfos['_route'] ?? '';
例如我在主页上,它有路由名称"home",在我离开另一个页面后例如编辑,如何在编辑页面上获取上一个路由的名称(这里它是家)?谢谢
您可以获取引荐来源网址并尝试 "match" 它与路由服务一起查看是否存在此路径的路由:
$referer = $request->headers->get('referer'); // get the referer, it can be empty!
if (!\is_string($referer) || !$referer) {
echo 'Referer is invalid or empty.';
return;
}
$refererPathInfo = Request::create($referer)->getPathInfo();
// try to match the path with the application routing
$routeInfos = $this->router->match($refererPathInfo);
// get the Symfony route name if it exists
$refererRoute = $routeInfos['_route'] ?? '';