dsh102123 2018-04-05 16:31
浏览 98
已采纳

多个控制器中的Symfony 3登录表单

I followed this tutorial on how to build a login form in Symfony 3 and everything works fine.

However I'd like to use the same login form on multiple pages ("/" and "/login"). Unfortunately I can always get only one of these pages working based on how I configure the "login_path" and "check_path" in security.yaml.

So it's either

form_login:
                  login_path: login
                  check_path: login

or

form_login:
                  login_path: /
                  check_path: /

I've tried to add another firewall specifically for the login page to use both at once, but without success, my form on /login would then seem to submit and would redirect to default_target_path, but the user wouldn't be logged in. I've also tried to set the 'action' variable in the function createForm in controller to make the login form submit to /login even on the index page, but that didn't work either.

Any ideas on how to solve this issue ?

  • 写回答

2条回答 默认 最新

  • dsm0688 2018-04-05 18:13
    关注

    Have you tried creating a second entry with a different name? I'm not sure it will work, but technically different providers with different names are allowed. And there's no requirement they actually have different providers or different implementations.

    security:
        # ...
    
        firewalls:
            main:
                # ...
                form_login:
                    login_path: login
                    check_path: login
            alternative
                # ...
                form_login:
                    login_path: /
                    check_path: /
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 数据库获取信息反馈出错,直接查询了ref字段并且还使用了User文档的_id而不是自己的
  • ¥15 将安全信息用到以下对象时发生以下错误:c:dumpstack.log.tmp 另一个程序正在使用此文件,因此无法访问
  • ¥15 速度位置规划实现精确定位的问题
  • ¥15 代码问题:df = pd.read_excel('c:\User\18343\Desktop\wpsdata.xlxs')路径读不到
  • ¥15 为什么视频算法现在全是动作识别?
  • ¥15 编写一段matlab代码
  • ¥15 用Python做岩石类别鉴定软件
  • ¥15 关于调取、提交更新数据库记录的问题
  • ¥15 之前删了盘从下vs2022遇见这个问题 搞了一整天了
  • ¥15 从Freecad中宏下载的DesignSPHysics,出现如下问题是什么原因导致的(语言-python)