我正在尝试在Symfony 2项目中实现更改密码功能.我User在validation.yml文件中有验证规则的实体.在User实体中,我有字段" password",其中包含验证约束validation.yml.
我创建了带有2个字段' password'和' confirmPasswod'的表单.我想对'password'字段使用我的实体验证约束,并检查' passwod'和' confirmPassword'字段之间的相等性.在我的控制者中,我写道
$form = $this->createForm(new SymfonyForm\ChangePasswordType(), new Entity\User());
if ($form->isValid())
{..............}
Run Code Online (Sandbox Code Playgroud)
在"用户"实体中,我没有"confirmPasswod"字段.所以我得到错误:
Neither property "confirmPassword" nor method "getConfirmPassword()" nor method "isConfirmPassword()" exists in class
Run Code Online (Sandbox Code Playgroud)
有没有办法对某些表单字段使用基于实体的表单验证而不为其他表单字段使用基于实体的验证?提前致谢.
jku*_*vic 16
在SymfonyForm\ChangePasswordType你可以使用这样的东西:
$builder->add('password', 'repeated', array(
'type' => 'password',
'first_name' => 'Password',
'second_name' => 'Password confirmation',
'invalid_message' => 'Passwords are not the same',
));
Run Code Online (Sandbox Code Playgroud)
从Symfony 2.1开始,您可以配置选项以避免损坏元素名称(如注释中所述)
$builder->add('password', 'repeated', array(
// … the same as before
'first_name' => 'passwd',
'second_name' => 'passwd_confirm',
// new since 2.1
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Password confirmation'),
));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2293 次 |
| 最近记录: |