Skip to content

Instantly share code, notes, and snippets.

Created February 2, 2013 03:00
Show Gist options
  • Save anonymous/4695939 to your computer and use it in GitHub Desktop.
Save anonymous/4695939 to your computer and use it in GitHub Desktop.
Symfony2 バリデーション callbanck制約を使う ※groups指定をしないと有効にならない
validation.ymlに
constraints:
- Callback:
methods: [isEmailConfirmEqual]
groups: [registration]
フォームエンティティクラスに
public function isEmailConfirmEqual(ExecutionContext $context)
{
if ($this->email != $this->email_confirm) {
$propertyPath = $context->getPropertyPath() . '.email_confirm';
$context->addViolationAtPath($propertyPath, 'メールアドレスが一致していません');
return;
}
 }
フォームクラスに
public function getDefaultOptions(array $options) {
return array(
'validation_groups' => array('registration')
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment