【问题标题】:Symfony 4 FOSUserBundle Custom Routes - Add prefix and subpagesSymfony 4 FOSUserBundle 自定义路由 - 添加前缀和子页面
【发布时间】:2018-11-21 04:39:49
【问题描述】:

使用 Symfony 4 和 FOSUserBundle 构建应用程序。

(用户的个人资料 UI 是一组选项卡。)

我想为配置文件中的每个选项卡设置一个子路径,因此每个选项卡都在它自己的页面/路径上。

例如 myapp.com/profile/dashboard

例如 myapp.com/profile/bookings

执行此操作的基本步骤是什么?

PS 如果我想删除路由的“/profile”部分怎么办:

例如 myapp.com/dashboard

或使用动态的,例如用户帐号“/11123”

例如 myapp.com/11123/dashboard

【问题讨论】:

    标签: php symfony fosuserbundle


    【解决方案1】:

    没有特殊的步骤。您可以完全忽略 FOS 路由,只需 评论config/routes/fos_user.yaml 中的定义:

    #fos_user:
    #    resource: "@FOSUserBundle/Resources/config/routing/all.xml"
    

    您也可以忽略某些部分(将其注释掉)并使用 FOS 路由的其他部分:

    #fos_user_profile:
    #    resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
    
    fos_user_register:
        resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
        prefix: /security
    
    fos_user_login:
        resource: "@FOSUserBundle/Resources/config/routing/security.xml"
        prefix: /security
    

    然后把你自己的路线放在config/routes/annotations.yaml:

    /myapp.com/profile/dashboard/
    /myapp.com/profile/bookings/
    

    并根据需要进行处理。如果您需要覆盖 FOS 控制器,请检查:

    Overriding Default FOSUserBundle Controllers

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-15
      • 1970-01-01
      • 1970-01-01
      • 2018-11-08
      • 1970-01-01
      • 2019-05-14
      • 2019-03-15
      • 2020-07-03
      相关资源
      最近更新 更多