【问题标题】:Symfony redirect user to url countrySymfony 将用户重定向到 url 国家
【发布时间】:2017-10-15 13:51:41
【问题描述】:

我正在寻找一个 PHP / Symfony 代码,以根据用户的连接位置 www.mondomain.fr/fr 和 www.mondomaine.fr/pt 等将用户重定向到另一个链接......我该怎么做?我已经在我的道路中加入了这个:

/**
 * @Route("/{_locale}", name="homepage")
 *
 */
public function indexAction(Request $request)
{
    $em = $this->getDoctrine()->getManager();
    $boutton = $em->getRepository('AppBundle:Boutton')->findAll();
    $image = $em->getRepository('AppBundle:Images')->findAll();

    // replace this example code with whatever you need
    return $this->render('default/index.html.twig', array(
        'base_dir' => realpath($this->container->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
        'boutton' => $boutton,
        'images' => $image
    ));
}

谢谢

【问题讨论】:

    标签: php symfony


    【解决方案1】:

    其中一种解决方案(不是 PHP 的)是基于浏览器语言进行重定向,您可以找到答案here

    您还可以检测 IP 并基于此重定向,您可以使用 this 库获取 IP 地址的国家/地区,然后基于此重定向。

    【讨论】:

      猜你喜欢
      • 2013-11-08
      • 1970-01-01
      • 2012-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多