@@ -36,7 +36,7 @@ You have a simple ``User`` entity mapped to the database::
36
36
protected $id;
37
37
38
38
/**
39
- * @ORM\Column(type="string", length=255)
39
+ * @ORM\Column(type="string", length=255)
40
40
* @Assert\NotBlank()
41
41
* @Assert\Email()
42
42
*/
@@ -46,7 +46,7 @@ You have a simple ``User`` entity mapped to the database::
46
46
* @ORM\Column(type="string", length=255)
47
47
* @Assert\NotBlank()
48
48
*/
49
- protected $password ;
49
+ protected $plainPassword ;
50
50
51
51
public function getId()
52
52
{
@@ -63,15 +63,14 @@ You have a simple ``User`` entity mapped to the database::
63
63
$this->email = $email;
64
64
}
65
65
66
- public function getPassword ()
66
+ public function getPlainPassword ()
67
67
{
68
- return $this->password ;
68
+ return $this->plainPassword ;
69
69
}
70
70
71
- // stupid simple encryption (please don't copy it!)
72
- public function setPassword($password)
71
+ public function setPlainPassword($password)
73
72
{
74
- $this->password = sha1( $password) ;
73
+ $this->plainPassword = $password;
75
74
}
76
75
}
77
76
@@ -82,9 +81,9 @@ the class.
82
81
83
82
.. note ::
84
83
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
86
85
to implement the :ref: `UserInterface<book-security-user-entity> ` of the
87
- security component .
86
+ security component.
88
87
89
88
Create a Form for the Model
90
89
---------------------------
@@ -103,7 +102,7 @@ Next, create the form for the ``User`` model::
103
102
public function buildForm(FormBuilder $builder, array $options)
104
103
{
105
104
$builder->add('email', 'email');
106
- $builder->add('password ', 'repeated', array(
105
+ $builder->add('plainPassword ', 'repeated', array(
107
106
'first_name' => 'password',
108
107
'second_name' => 'confirm',
109
108
'type' => 'password',
@@ -127,19 +126,17 @@ password). The ``data_class`` option tells the form the name of data class
127
126
128
127
.. tip ::
129
128
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 `.
131
130
132
131
Embedding the User form into a Registration Form
133
132
------------------------------------------------
134
133
135
134
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.
139
138
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"::
143
140
144
141
// src/Acme/AccountBundle/Form/Model/Registration.php
145
142
namespace Acme\AccountBundle\Form\Model;
@@ -207,8 +204,8 @@ Next, create the form for this ``Registration`` model::
207
204
208
205
You don't need to use special method for embedding the ``UserType `` form.
209
206
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 .
212
209
213
210
Handling the Form Submission
214
211
----------------------------
@@ -270,4 +267,6 @@ the validation and saves the data into the database::
270
267
}
271
268
272
269
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.
0 commit comments