我尝试使用简单的管理包添加密码重复,但我不太清楚如何做到这一点。 我在我的实体中有这两个属性
/**
* @var string
*
* @Assert\NotBlank()
* @Assert\Length(max="4096")
*/
private $plainPassword;
/**
* @var string
*
* @ORM\Column(type="string", length=64)
*/
private $password;
如果我在config.yml文件中添加一个类型:重复它只创建两个输入字段但不创建密码类型。我相信形式应该是这样的。
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
由于
编辑
好的,所以我扩展了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错误密码不能为空。
答案 0 :(得分:1)
你可以在映射你的实体的config.yml中设置它,例如我有这个:
easy_admin:
entities:
Usuario:
class: AppBundle\Entity\Usuario
controller: AppBundle\Controller\UsuarioController
form:
fields:
- 'documento'
- 'codigo'
- 'nombre'
- 'apellido'
- 'email'
- { property: 'passwordEnClaro', type: 'repeated', type_options: { type: 'password', invalid_message: 'Las dos contraseñas deben coincidir', first_options: { label: 'Contraseña' }, second_options: { label: 'Confirmar Contraseña' }, required: false } }
- { property: 'rol', type: 'choice', type_options: { choices: { 'ROLE_ADMIN': 'ROLE_ADMIN', 'ROLE_FUNCIONARIO': 'ROLE_FUNCIONARIO', 'ROLE_DOCENTE': 'ROLE_DOCENTE', 'ROLE_ESTUDIANTE': 'ROLE_ESTUDIANTE' }, attr: { 'data-widget': 'select2' } } }
- { property: 'dependencia', type: 'easyadmin_autocomplete', type_options: { class: 'AppBundle\Entity\Dependencia' } }
注意:控制器定义仅适用于PreUpdate。
答案 1 :(得分:1)
尝试使用类型Symfony \ Component \ Form \ Extension \ Core \ Type \ PasswordType而不是密码。
form:
fields:
- {'property': 'plainPassword', type: 'repeated', type_options: { type: Symfony\Component\Form\Extension\Core\Type\PasswordType, required: false, first_options: {label: 'label.password'}, second_options: {label: 'label.password_confirmation'} } }