我正在尝试在FOSUserBundle的ProfileFormType中添加电子邮件字段。
用户实体如下:
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
protected $email;
protected $emailCanonical;
public function __construct()
{
parent::__construct();
// your own logic
}
public function setEmail($email)
{
parent::setUsername($email);
return parent::setEmail($email);
}
public function setEmailCanonical($emailCanonical)
{
parent::setUsernameCanonical($emailCanonical);
return parent::setEmailCanonical($emailCanonical);
}
}
个人资料表单类型如下:
namespace UserBundle\Form\Type;
use Symfony\Component\Form\FormBuilderInterface;
use FOS\UserBundle\Form\Type\ProfileFormType as BaseType;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class ProfileFormType extends BaseType
{
public function __construct($class)
{
parent::__construct($class);
}
public function buildUserForm(FormBuilderInterface $builder, array $options)
{
parent::buildUserForm($builder, $options);
$builder->remove('username');
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'UserBundle\Entity\User'
));
}
public function getParent()
{
return 'fos_user_registration';
}
public function getName()
{
return 'app_user_profile';
}
}
服务是:
app.profile.form.type:
class: UserBundle\Form\Type\ProfileFormType
arguments: ["%fos_user.model.user.class%"]
tags:
- { name: form.type, alias: app_user_profile }
在配置中我添加了以下行:
profile:
form:
type: app_user_profile
什么都没发生。我做错了什么?