我在Symfony 3.4中创建表单捆绑用户
一切正常。我的注册表格有效。我可以注册用户。我也可以登录。 我尝试为成员创建编辑表单.i无法编辑密码成员。 我读了这个post,但我没有任何结果。任何人都知道我错在哪里
这是我的用户实体
/**
* @Assert\NotBlank()
* @Assert\Length(max=4096)
*/
private $plainPassword;
/**
* The below length depends on the "algorithm" you use for encoding
* the password, but this works well with bcrypt.
*
* @ORM\Column(type="string", length=64)
*/
private $password;
public function getPlainPassword()
{
return $this->plainPassword;
}
public function setPlainPassword($password)
{
$this->plainPassword = $password;
}
public function getPassword()
{
return $this->password;
}
public function setPassword($password)
{
$this->password = $password;
}
public function eraseCredentials()
{
}
用户类型
.
.
.
->add('oldPlainPassword', \Symfony\Component\Form\Extension\Core\Type\PasswordType::class, array(
'constraints' => array(
new \Symfony\Component\Security\Core\Validator\Constraints\UserPassword(),
),
'mapped' => false,
'required' => true,
'label' => 'Current Password',
))
->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat Password'),
))
;
}
.
.
.
我的控制器
.
.
.
/**
* @Route("/admin__/EditUser/{id}" ,name="editUser")
*/
public function EditUserAction(Request $request, $id)
{
.
.
.
if ($request->getMethod() == Request::METHOD_POST){
$form->handleRequest($request);
.
.
.
$password = $passwordEncoder->encodePassword($user, $user->getPlainPassword());
$user->setPassword($password);
.
.
.
$em->flush();
edit_user.html.twig
{{ form_row(form.plainPassword.second) }}
{{ form_row(form.plainPassword.first) }}
{{ form_row(form.oldPlainPassword) }}