Created
September 13, 2011 10:00
-
-
Save stefanosala/1213516 to your computer and use it in GitHub Desktop.
Esempio user registration form
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
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'; | |
} | |
} |
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
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; | |
} |
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
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... | |
} | |
} |
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
/** | |
* @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