Skip to content

Commit 99bb83c

Browse files
committed
minor #6592 [Form] Making the name property private to be more realistic (weaverryan)
This PR was merged into the 2.3 branch. Discussion ---------- [Form] Making the name property private to be more realistic Hack day ftw! | Q | A | ------------- | --- | Doc fix? | not really | New docs? | no | Applies to | all | Fixed tickets | n/a Commits ------- 3780adf [Form] Making the name property private to be more realistic
2 parents 53af34b + 3780adf commit 99bb83c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

cookbook/form/form_collections.rst

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,18 @@ objects::
6969

7070
class Tag
7171
{
72-
public $name;
73-
}
72+
private $name;
7473

75-
.. tip::
74+
public function getName()
75+
{
76+
return $this->name;
77+
}
7678

77-
The ``name`` property is public here, but it can just as easily be protected
78-
or private (but then it would need ``getName`` and ``setName`` methods).
79+
public function setName($name)
80+
{
81+
$this->name = $name;
82+
}
83+
}
7984

8085
Then, create a form class so that a ``Tag`` object can be modified by the user::
8186

@@ -162,10 +167,10 @@ In your controller, you'll now initialize a new instance of ``TaskType``::
162167
// dummy code - this is here just so that the Task has some tags
163168
// otherwise, this isn't an interesting example
164169
$tag1 = new Tag();
165-
$tag1->name = 'tag1';
170+
$tag1->setName('tag1');
166171
$task->getTags()->add($tag1);
167172
$tag2 = new Tag();
168-
$tag2->name = 'tag2';
173+
$tag2->setName('tag2');
169174
$task->getTags()->add($tag2);
170175
// end dummy code
171176

0 commit comments

Comments
 (0)