How can I change the data receiving format in a FosUserBundle form?

I'm trying to create an API app using the FosUserBundle functions.

I can not change the data transmission format, in fact, if I send the request with the parameters built in this way, works:

{"fos_user_registration_form":
    {
        "username":"test",
        "plainPassword":
                           {
                               "first":"123456",
                               "second":"123456"
                           },
        "email":"test@test.com",
        "name":"test"
     }
}

But if I change the string fos_user registration form , for example with the string user , to make it cleaner being a public API, no longer works.

Is possible to change this format?

Thank you all for the answers.


I think you should create another action (rest controller/action) which handles the required information, which would be:

{
        "username":"test",
        "plainPassword": "123456",
        "email":"test@test.com",
        "name":"test"
}

And in there you can process the validation manually using the form or not and the save it using the manager.

I don't have the detailed process on how to do it but you can basically use the services which fos_user registers on the DI container, like:

fos_user.registration.form.factory FOSUserBundleFormFactoryFormFactory
fos_user.registration.form.type FOSUserBundleFormTypeRegistrationFormType fos_user.user_manager FOSUserBundleDoctrineUserManager

This will basically allow you to do all the validation necessary but customize the request body from the final API user, plus to that you have more control and will be safe on updates.


I finally found the solution to my problem!

Trivially there is an option in the configuration of FosUserBundle called name under form option.

I post below my configuration for a better comprehension ( in this case I want to change the form registration name):

fos_user:
db_driver: orm
firewall_name: login
user_class: SBUserBundleEntityUser
registration:
    form:
        name: user

Best regards.

链接地址: http://www.djcxy.com/p/91692.html

上一篇: FOSUserBundle

下一篇: 如何更改FosUserBundle表单中的数据接收格式?