Created
February 2, 2013 03:00
-
-
Save anonymous/4695939 to your computer and use it in GitHub Desktop.
Symfony2 バリデーション callbanck制約を使う
※groups指定をしないと有効にならない
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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