Php Symfony 2验证
我有一个关于通过实体和验证配置文件进行symfony 2验证的问题。下面是问题的解释 我有一个用户帐户设置的实体,它有5个属性-子域、电子邮件、旧密码、密码和新密码 我的配置文件如下:Php Symfony 2验证,php,validation,symfony,Php,Validation,Symfony,我有一个关于通过实体和验证配置文件进行symfony 2验证的问题。下面是问题的解释 我有一个用户帐户设置的实体,它有5个属性-子域、电子邮件、旧密码、密码和新密码 我的配置文件如下: Backend\Builders\PageBundle\Entity\AccountSettings: properties: email: - Email: ~ oldPassword: - Symfony\Component\Security\Core\Vali
Backend\Builders\PageBundle\Entity\AccountSettings:
properties:
email:
- Email: ~
oldPassword:
- Symfony\Component\Security\Core\Validator\Constraints\UserPassword:
message: "Wrong value for your current password"
constraints:
- Expression:
expression: "this.passwordMatch()"
message: "Passwords don`t match"
我的问题是-如何使用此实体进行验证,并选择仅对特定项目(例如电子邮件)执行验证。
下面是我目前用于此验证的代码,但它要求满足所有验证规则,以便验证成功:
$accountSettings = new AccountSettings();
$accountSettings->email = $_POST['email'];
$validator = $this->get('validator');
$errors = $validator->validate($accountSettings);
然后你应该使用。它允许你做
Backend\Builders\PageBundle\Entity\AccountSettings:
properties:
email:
- Email: { groups: [xxx_group] }
oldPassword:
# ...
查看中提供的答案。感谢您快速准确的回答。这正是我所需要的。祝你好运,伙计。
$errors = $validator->validate($accountSettings, array('xxx_group'));