Created
June 11, 2010 20:23
-
-
Save jmikola/434986 to your computer and use it in GitHub Desktop.
Using grouped constraints with Symfony 2 Forms
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
<?php | |
/* Since the group name is specified, "Default" will be assigned automatically and | |
* the implicity group name "Registration" (based on containing class' name) will | |
* also not be assigned. | |
*/ | |
class Registration | |
{ | |
public $field; | |
public static function loadValidatorMetadata(ClassMetadata $metadata) | |
{ | |
$metadata | |
->addPropertyConstraint('field', new MinLength(array( | |
'limit' => 4, | |
'groups' => 'Test' | |
)); | |
} | |
} | |
$registration = new Registration(); | |
$form = new RegistrationForm('registration', $registration); | |
// See: http://github.com/bschussek/symfony/commit/faed30dfec570ca474af7498700df9816cf985e1 | |
$form->setValidationGroups('Test'); | |
if ($this->getRequest()->request->has('registration')) { | |
$form->bind($this->getRequest()->request->get('registration')); | |
if ($form->isValid()) { | |
// Do something | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment