Adding extended profile entity to FOS UserBundle

前端 未结 1 900
灰色年华
灰色年华 2021-02-09 02:01

I am trying to extend the FOS UserBundle to allow for extended profile entities to hold additional information in addition to the basic UserBundle fields. Because I have multip

1条回答
  •  轮回少年
    2021-02-09 02:29

    If you are using MySQL and php for your entities definition, then you have to create your Entity as follow:

    The second step is to create you form type asking the fields you want:

    // src/Acme/UserBundle/Form/Type/RegistrationFormType.php
    add('phone');
            $builder->add('language');
    
            //...............
            //Add all your properties here with $builder->add('property name')
        }
    
        public function getName()
        {
            return 'acme_user_registration';
        }
    }
    

    Now you need to let the bundle know that you want to use your custom form:

    # src/Acme/UserBundle/Resources/config/services.yml
    services:
        acme_user.registration.form.type:
            class: Acme\UserBundle\Form\Type\RegistrationFormType
            arguments: [%fos_user.model.user.class%]
            tags:
                - { name: form.type, alias: acme_user_registration }
    

    The last step is about telling FOSUserBundle that it will use your form type instead of the default one:

    # app/config/config.yml
    fos_user:
        # ...
        registration:
            form:
                type: acme_user_registration
    

    Source:

    https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md#step-3-create-your-user-class
    https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_forms.md

    0 讨论(0)
提交回复
热议问题