Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created September 26, 2011 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weaverryan/1242396 to your computer and use it in GitHub Desktop.
Save weaverryan/1242396 to your computer and use it in GitHub Desktop.
Example of validating a scalar value in Symfony2
<?php
// .. other things
use Symfony\Component\Validator\Constraints\Email;
class DefaultController
{
public function someAction()
{
$emails = // ... some way to get an email array
$validator = $this->get('validator');
$constraint = new Email();
$goodEmails = array();
$badEmails = array();
foreach ($emails as $email) {
$errors = $validator->validateValue($email, $constraint);
if (count($errors) == 0) {
$goodEmails[] = $email;
} else {
$badEmails[] = $email;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment