doubaomao9304 2017-10-14 19:09
浏览 47
已采纳

Symfony将用户重定向到url国家/地区

I'm looking for a PHP / Symfony code to redirect the user to another link according to his place of connection www.mondomain.fr/fr and www.mondomaine.fr/pt etc ... How can I do this ? I have included in my roads this already:

/**
 * @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
    ));
}

Thank you

  • 写回答

1条回答 默认 最新

  • duanmu1736 2017-10-15 05:51
    关注

    One of the solutions (not a PHP one) is to redirect based on browser language, you can find answer here.

    You can also detect IP and redirect based on that, you can use this library to get the country/locale of the IP address and then redirect based on that.

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

报告相同问题?