Forked from anonymous/symfony2_validation_callback_constraint
Last active
December 12, 2015 02:08
-
-
Save EuphoryX1/4696015 to your computer and use it in GitHub Desktop.
Callback制約を使って2つのフォームプロパティを参照してバリデーションを実施する。Callback制約をどのフォームに適用するかを指定するために、groupsの指定が必要
This file contains hidden or 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