我创建了一个ORM用户类,并添加了一个名为" name" 的新属性。我也创建了一个新的RegistrationFormType。问题是注册表单只显示新字段" name" 以及FOSuserBundle提供的其他字段(email,usreneme,password')。
// src/Boutique/UserBundle/Form/RegistrationFormType.php
<?php
namespace Boutique\UserBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;
class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', 'text')
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Boutique\UserBundle\Entity\User'
));
}
public function getName()
{
return 'boutique_user_registration';
}
}
config.yml
fos_user:
db_driver: orm
firewall_name: main
user_class: Boutique\UserBundle\Entity\User
registration:
confirmation:
from_email: # Use this node only if you don't want the global email address for the confirmation email
address: addd@hous.fr
sender_name: no-reply
enabled: false # change to true for required email confirmation
template: FOSUserBundle:Registration:email.txt.twig
form:
type: boutique_user_registration
name: fos_user_registration_form
validation_groups: [Registration, Default]
services.yml
services:
boutique_user.registration.form.type:
class: Boutique\UserBundle\Form\RegistrationFormType
arguments: [%fos_user.model.user.class%]
tags:
- { name: form.type, alias: boutique_user_registration }
答案 0 :(得分:0)
您可以通过将自定义UserBundle定义为FOSUserBundle的子项来覆盖默认的RegistrationFormType.php:
<?php
namespace Boutique\UserBundle\Form;;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class BoutiqueUserBundle extends Bundle
{
public function getParent()
{
return 'FOSUserBundle';
}
}
然后要覆盖FormType,只需将/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Form/Type/ResettingFormType.php
复制到/src/Boutique/UserBundle/Form/Type/RegistrationFormType.php
即可。添加您的姓名字段和完成。