How to override register form FosUserBundle?

风流意气都作罢 提交于 2019-12-11 11:44:38

问题


I want to override some of FOSUserBundle forms ( registration form ) So I followed the documentation and I cant understand why I keep getting the same error :

Attempted to load class "RegistrationFormType" from namespace "OC\UserBundle\Form\Type". Did you forget a "use" statement for "FOS\UserBundle\Form\Type\RegistrationFormType"? 500 Internal Server Error - ClassNotFoundException.

These are my files:

RegistrationFormType.php:

<?php
namespace OC\UserBundle\Form\Type;

use Symfony\Component\Form\FormBuilder;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;

class RegistrationFormType extends BaseType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        parent::buildForm($builder, $options);

        $builder->add('telephone');
    }

    public function getName()
    {
        return 'oc_user_registration';
    }
}    

Service.yml of the OCUserBundle:

services:
    oc_user_registration:
        class: OC\UserBundle\Form\Type\RegistrationFormType
        tags:
            - {name: form.type, alias: oc_user_registration}

and I configured the project to use my form type when the user tries to register in the app/Ressources/config.yml:

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: OC\UserBundle\Entity\User
    registration:
        form:
            type: oc_user_registration

Please can someone tell me what's wrong here?


回答1:


Solved this. The error was that the path to the path to the FormType file wasn't the same as the namespace. Thank you anyway.




回答2:


You see https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_forms.md

All is explain, I already use and is ok




回答3:


add his function to your registration form type

public function getParent() { return 'fos_user_registration'; }



来源:https://stackoverflow.com/questions/31305417/how-to-override-register-form-fosuserbundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!