Skip to content

Commit 0a23fb7

Browse files
committed
[cookbook][doctrine] Tweaks after a read-through of #1599
1 parent 57b2a8c commit 0a23fb7

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

cookbook/doctrine/registration_form.rst

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ You have a simple ``User`` entity mapped to the database::
3636
protected $id;
3737

3838
/**
39-
* @ORM\Column(type="string", length=255)
39+
* @ORM\Column(type="string", length=255)
4040
* @Assert\NotBlank()
4141
* @Assert\Email()
4242
*/
@@ -46,7 +46,7 @@ You have a simple ``User`` entity mapped to the database::
4646
* @ORM\Column(type="string", length=255)
4747
* @Assert\NotBlank()
4848
*/
49-
protected $password;
49+
protected $plainPassword;
5050

5151
public function getId()
5252
{
@@ -63,15 +63,14 @@ You have a simple ``User`` entity mapped to the database::
6363
$this->email = $email;
6464
}
6565

66-
public function getPassword()
66+
public function getPlainPassword()
6767
{
68-
return $this->password;
68+
return $this->plainPassword;
6969
}
7070

71-
// stupid simple encryption (please don't copy it!)
72-
public function setPassword($password)
71+
public function setPlainPassword($password)
7372
{
74-
$this->password = sha1($password);
73+
$this->plainPassword = $password;
7574
}
7675
}
7776

@@ -82,9 +81,9 @@ the class.
8281

8382
.. note::
8483

85-
If you want to integrate this User within the security system,you need
84+
If you want to integrate this User within the security system, you need
8685
to implement the :ref:`UserInterface<book-security-user-entity>` of the
87-
security component .
86+
security component.
8887

8988
Create a Form for the Model
9089
---------------------------
@@ -103,7 +102,7 @@ Next, create the form for the ``User`` model::
103102
public function buildForm(FormBuilder $builder, array $options)
104103
{
105104
$builder->add('email', 'email');
106-
$builder->add('password', 'repeated', array(
105+
$builder->add('plainPassword', 'repeated', array(
107106
'first_name' => 'password',
108107
'second_name' => 'confirm',
109108
'type' => 'password',
@@ -127,19 +126,17 @@ password). The ``data_class`` option tells the form the name of data class
127126

128127
.. tip::
129128

130-
To explore more things about the form component, read this documentation :doc:`file</book/forms>`.
129+
To explore more things about the form component, read :doc:`/book/forms`.
131130

132131
Embedding the User form into a Registration Form
133132
------------------------------------------------
134133

135134
The form that you'll use for the registration page is not the same as the
136-
form for used to simply modify the ``User`` (i.e. ``UserType``). The registration
137-
form will contain further fields like "accept the terms", whose value is
138-
won't be stored into database.
135+
form used to simply modify the ``User`` (i.e. ``UserType``). The registration
136+
form will contain further fields like "accept the terms", whose value won't
137+
be stored in the database.
139138

140-
In other words, create a second form for registration, which embeds the ``User``
141-
form and adds the extra field needed. Start by creating a simple class which
142-
represents the "registration"::
139+
Start by creating a simple class which represents the "registration"::
143140

144141
// src/Acme/AccountBundle/Form/Model/Registration.php
145142
namespace Acme\AccountBundle\Form\Model;
@@ -207,8 +204,8 @@ Next, create the form for this ``Registration`` model::
207204

208205
You don't need to use special method for embedding the ``UserType`` form.
209206
A form is a field, too - so you can add this like any other field, with the
210-
expectation that the corresponding ``user`` property will hold an instance
211-
of the class ``UserType``.
207+
expectation that the ``Registration.user`` property will hold an instance
208+
of the ``User`` class.
212209

213210
Handling the Form Submission
214211
----------------------------
@@ -270,4 +267,6 @@ the validation and saves the data into the database::
270267
}
271268

272269
That's it! Your form now validates, and allows you to save the ``User``
273-
object to the database.
270+
object to the database. The extra ``terms`` checkbox on the ``Registration``
271+
model class is used during validation, but not actually used afterwards when
272+
saving the User to the database.

cookbook/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* :doc:`/cookbook/doctrine/reverse_engineering`
4242
* :doc:`/cookbook/doctrine/multiple_entity_managers`
4343
* :doc:`/cookbook/doctrine/custom_dql_functions`
44+
* :doc:`/cookbook/doctrine/registration_form`
4445

4546
* :doc:`/cookbook/email/index`
4647

0 commit comments

Comments
 (0)