Skip to content

Commit 1cd3ead

Browse files
committed
[cookbook][doctrine] Updating the registration form cookbook entry for 2.1 - see #1599
1 parent ad8557a commit 1cd3ead

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

cookbook/doctrine/registration_form.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ Next, create the form for the ``User`` model::
9494
namespace Acme\AccountBundle\Form\Type;
9595

9696
use Symfony\Component\Form\AbstractType;
97-
use Symfony\Component\Form\FormBuilder;
97+
use Symfony\Component\Form\FormBuilderInterface;
98+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
9899

99100
class UserType extends AbstractType
100101
{
101-
public function buildForm(FormBuilder $builder, array $options)
102+
public function buildForm(FormBuilderInterface $builder, array $options)
102103
{
103104
$builder->add('email', 'email');
104105
$builder->add('plainPassword', 'repeated', array(
@@ -108,9 +109,11 @@ Next, create the form for the ``User`` model::
108109
));
109110
}
110111

111-
public function getDefaultOptions(array $options)
112+
public function setDefaultOptions(OptionsResolverInterface $resolver)
112113
{
113-
return array('data_class' => 'Acme\AccountBundle\Entity\User');
114+
$resolver->setDefaults(array(
115+
'data_class' => 'Acme\AccountBundle\Entity\User'
116+
));
114117
}
115118

116119
public function getName()
@@ -184,11 +187,11 @@ Next, create the form for this ``Registration`` model::
184187
namespace Acme\AccountBundle\Form\Type;
185188

186189
use Symfony\Component\Form\AbstractType;
187-
use Symfony\Component\Form\FormBuilder;
190+
use Symfony\Component\Form\FormBuilderInterface;
188191

189192
class RegistrationType extends AbstractType
190193
{
191-
public function buildForm(FormBuilder $builder, array $options)
194+
public function buildForm(FormBuilderInterface $builder, array $options)
192195
{
193196
$builder->add('user', new UserType());
194197
$builder->add('terms', 'checkbox', array('property_path' => 'termsAccepted'));
@@ -250,7 +253,7 @@ the validation and saves the data into the database::
250253

251254
$form = $this->createForm(new RegistrationType(), new Registration());
252255

253-
$form->bindRequest($this->getRequest());
256+
$form->bind($this->getRequest());
254257

255258
if ($form->isValid()) {
256259
$registration = $form->getData();

0 commit comments

Comments
 (0)