2

我正在尝试使用简单的管理包添加密码重复,但我不太确定该怎么做。我的实体中有这两个属性

/**
 * @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

谢谢

  • 编辑好的,所以我扩展了 AdminControllerJavierEguiluz\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错误密码不能为空。

4

2 回答 2

2

尝试输入 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'} } }
于 2017-12-28T16:23:56.140 回答
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 使用。

于 2017-05-06T22:04:03.003 回答