doushu9253 2017-04-10 12:52
浏览 43
已采纳

在使用FOSUserBundle注册后,如何重定向到动态自定义路由

I've been looking for a while for this, but can't find the answer.

Expected behavior:

  • User goes on a product page
  • User wants to buy the product, so he needs to login / register (with a modal)
  • User doesn't have an account so he registers
  • After registration (there is no email confirmation), user is signed in and redirected to the current product page
  • User can proceed to checkout, etc...

This behavior is working in the case of a login, with the use of the _target_path parameter in the form.

However, this parameter does not apply in registration. This is kinda annoying, where did I miss something out ? I am looking into implementing a Listener on the registration success event but it seems really odd to not being as simple as for the login form.

Edit: found my solution, see my own answer below

  • 写回答

2条回答 默认 最新

  • dongwu3747 2017-04-10 13:34
    关注

    Answering for those wondering too.

    TL;DR : the registration process does not follow the login's

    Thanks to @yceruto for the comment.

    I made a quick listener on the REGISTRATION_SUCCESS event:

    /**
     * @param FormEvent $event
     */
    public function redirectOnRegistration(FormEvent $event)
    {
        $route = $event->getRequest()->headers->get('referer', $this->router->generate('homepage'));
        $response = new RedirectResponse($route);
        $event->setResponse($response);
    }
    

    (I redirect on homepage if there is no referer).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算