Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save frosas/1933556 to your computer and use it in GitHub Desktop.
Save frosas/1933556 to your computer and use it in GitHub Desktop.
<?php
// ...
$user = new User;
$form = $this->createFormBuilder($user)
->add('email', 'email')
->getForm();
if ($request->getMethod() == 'POST') {
$em = $this->get('doctrine')->getEntityManager();
$form->bindRequest($request);
if ($form->isValid()) {
$em = $this->get('doctrine')->getEntityManager();
$em->persist($user);
$em->flush();
// ...
}
// ...
<?php
// ...
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity
* @UniqueEntity("email")
*/
class User {
// ...
/**
* @Constraints\Email
* @ORM\Column(type="string", length=255, unique=true)
*/
private $email;
function setEmail($email) {
$this->email = $email;
}
function getEmail() {
return $this->email;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment