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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度