我正在尝试使用简单的管理包添加密码重复,但我不太确定该怎么做。我的实体中有这两个属性
/**
* @var string
*
* @Assert\NotBlank()
* @Assert\Length(max="4096")
*/
private $plainPassword;
/**
* @var string
*
* @ORM\Column(type="string", length=64)
*/
private $password;
如果我添加一个 type: 在我的 config.yml 文件中重复,它只会创建两个输入字段,而不是 Password 类型。我相信形式应该是这样的。
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', EmailType::class)
->add('username', TextType::class)
->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat Password'),
)
)
->add('termsAccepted', CheckboxType::class, array(
'mapped' => false,
'constraints' => new IsTrue(),
)
);
}
我已经检查了简单的管理包文档,但我有点迷失了如何实现它。https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/book/7-complex-dynamic-backends.md
谢谢
编辑好的,所以我扩展了 AdminController
JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController
public function createNewForm($entity, array $entityProperties) { $userForm = parent::createNewForm($entity, $entityProperties); if ($entity instanceof User) { $userForm->remove('password'); $userForm->add('plainPassword', RepeatedType::class, array( 'type' => PasswordType::class, 'first_options' => array('label' => 'Password'), 'second_options' => array('label' => 'Re-enter Password') )); } return $userForm; }
但是现在当我尝试插入/提交表单时,sql错误密码不能为空。