Symfony2:如何使用FOSUserBundle构建多个注册表单 [英] Symfony2: How to build multiple registration forms with FOSUserBundle

查看:61
本文介绍了Symfony2:如何使用FOSUserBundle构建多个注册表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绝对不是Symfony2的新手,但是已经爱上了这个框架.

我有一个项目,需要具有3种不同的用户类型.

一个将是超级管理员,另外两个将是普通用户,但具有不同的配置文件布局.配置文件的布局不同,意味着这两种用户类型的注册表单在注册后必须在应用程序中具有不同的表单字段和不同的布局.

我想我有个主意(不知道以后是否可以)在注册后如何管理用户.但是到目前为止,我还不了解如何构建将从FOSUserBundle扩展的两种不同的注册表单.

据我所知,FOSUB在配置中只有一点要设置注册,并且不能有多个注册:"

在config.yml中,我有:

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: Company\UserBundle\Entity\User
    registration:
        confirmation: { enabled: true }

security.yml:

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    main:
        pattern:  ^/
        form_login:
            provider: fos_userbundle
            csrf_provider:  form.csrf_provider
        logout:       true
        anonymous:    true

我的想法是创建三个扩展FOSUB的包,但是文档表明只有一个包可以将FOSUB声明为父包.

另一个选项(来自文档)是扩展ContainerAware,以实现所有原始方法.但是即使在这种情况下,我也无法理解如何配置app/config/{config | security | routing} .yml以具有例如将使用FOSUB和自定义表单的/register_employee,/register_manager链接? /p>

请为我指明正确的方向. 谢谢.

解决方案

FOSUserBundle不是提供用户身份验证,而是管理用户.该捆绑包为您提供了更好的结构来管理您的应用程序的用户.如果您看一下代码,将会发现用于默认注册和其他用户活动的控制器.

理想情况下,您可能想编写自己的控制器并利用该捆绑包仅存储和检索用户.当您要管理多个注册/登录表单时,尤其需要这样做.

一旦您开始考虑仅FOSUserBundle仅用于管理用户而不是对其进行身份验证/注册,事情似乎会更加清楚.

您可能还希望查看 https://github.com/sonata-project/SonataUserBundle,它提供SonataAdminBundle和FOSUserBundle之间的集成.

I'm absolutely new to Symfony2 but already in love with this framework.

I'm having a project that requires to have 3 different user types.

One will be super admin, other two will be a regular users but with different profile layouts. Different layouts for profile means registration form for those two user types must have different form fields and different layouts in the application after registration.

I think I've got the idea (don't know if that will be OK later) how to manage users after registration. But for now I don't understand how to build two different registration forms that will be extended from FOSUserBundle.

As far as I understand FOSUB have only one point in the configuration where registration is set up and cannot have multiple "registration:"

In the config.yml I have:

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: Company\UserBundle\Entity\User
    registration:
        confirmation: { enabled: true }

security.yml:

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    main:
        pattern:  ^/
        form_login:
            provider: fos_userbundle
            csrf_provider:  form.csrf_provider
        logout:       true
        anonymous:    true

My idea is to create three different bundles that extends FOSUB, but documentation says that only one bundle can declare FOSUB as parent.

Another option (from documentation) is to extend ContainerAware implementing all original methods. But even in this case, I don't get it how I have to configure app/config/{config|security|routing}.yml to have for instance /register_employee, /register_manager links that will use FOSUB and my custom forms?

Please point me to right direction. Thanks.

解决方案

FOSUserBundle is not to provide authentication of users but to manage users. The bundle provides you a better structure to manage users for your application. If you take a look at the code you will find controllers that are used for the default registration and other user activities.

Ideally you would want to write your own controller and make use of the bundle to only store and retrieve users. This is especially required when you want to manage multiple registration/login forms.

Things would seem clearer once you start to consider FOSUserBundle only to manage users and not to authenticate/register them.

You might also want to look at https://github.com/sonata-project/SonataUserBundle, which provides integration between SonataAdminBundle and FOSUserBundle.

这篇关于Symfony2:如何使用FOSUserBundle构建多个注册表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆