dougong5285 2018-10-22 17:22
浏览 55
已采纳

用FOSUserBundle登录后如何重写路由?

I'm having an issue while using FOSUserBundle (dev-master) on Symfony 3.4.17.

The problem is that I'm not redirected where I want to be after having been logged in successfully, and I don't find how to rewrite the route where I want to be redirected.

I'm having this error message:

The _controller value "TICoreBundle:Default:index" maps to a "TI\CoreBundle\Controller\DefaultController" class, but this class was not found. Create this class or check the spelling of the class and its namespace.

I know that I could simply create a Default Controller in the TICoreBundle, and redirect using an indexAction.

But I'm pretty sure that this isn't an elegant solution.

Is there any place where I'm supposed to rewrite the route? I found this a bit disturbing since I used this Bundle in another project without any redirecting problem, and I don't find what is different between them.

EDIT: I solved my problem by adding:

# app/config/security.yml

form_login:

    default_target_path: after_login_route_name

as suggested here: https://symfony.com/doc/3.4/security/form_login.html

  • 写回答

1条回答 默认 最新

  • doudu7626 2018-10-22 18:34
    关注

    The most likely case is that the symfony firewall has some incorrect configurations.

    Check in you config files for the firewalls key under security. Under this section you should have a firewall configured for your form login (default is something like main -> form_login). Under this you can have one of the following:

    • default_target_path: the path where you will be redirected after login
    • always_use_default_target_path: together with default_target_path this will make sure that the user will always be redirected to the same page regardless of the page where he came from.
    • use_referer: this if set to "true" will use the previous page where the user was as the target path after login. This option can create some issues when combined with ajax calls.

    If noting is set under the firewall config the user will automatically be redirected to "/"

    Post an example of your symfony security configuration so that I can better understand the issue. Also the documentation on symfony website is decent, maybe you can get an idea of what is wrong from there https://symfony.com/doc/3.4/security/form_login.html

    Hope this helps, and if not give me more details about the issue and maybe we can fix it together.

    Alexandru Cosoi

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

报告相同问题?

悬赏问题

  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统