Skip to content

Instantly share code, notes, and snippets.

@stefanosala
Created September 13, 2011 10:00
Show Gist options
  • Save stefanosala/1213516 to your computer and use it in GitHub Desktop.
Save stefanosala/1213516 to your computer and use it in GitHub Desktop.
Esempio user registration form
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;
class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilder $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->add('userType');
}
public function getName()
{
return 'foo_user_registration';
}
}
use FOS\UserBundle\Entity\User as BaseUser;
/**
* @ORM\Entity
* @ORM\Table(name="user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer", nullable="false")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @orm\ManyToOne(targetEntity="UserType", inversedBy="users", cascade={"persist", "remove"})
* @orm\JoinColumn(name="userType", referencedColumnName="id")
*/
protected $userType;
}
class UsersController extends Controller
{
public function postUsersAction()
{
$form = $this->createForm(
$this->get('foo_user.registration.form.type'),
new User(),
array('validation_groups' => array('Registration')
));
$form->bind($this->getRequest()->get($form->getName()));
$form->isValid();
// ecc...
}
}
/**
* @ORM\Entity
* @ORM\Table(name="user_type")
*/
class UserType
{
/**
* @ORM\Id
* @ORM\Column(type="integer", nullable="false")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @orm\OneToMany(targetEntity="User", mappedBy="userType")
* @var User[]
*/
protected $users;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment