Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Form] Making the name property private to be more realistic #6592

Merged
merged 1 commit into from
May 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions cookbook/form/form_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ objects::

class Tag
{
public $name;
}
private $name;

.. tip::
public function getName()
{
return $this->name;
}

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

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

Expand Down Expand Up @@ -162,10 +167,10 @@ In your controller, you'll now initialize a new instance of ``TaskType``::
// dummy code - this is here just so that the Task has some tags
// otherwise, this isn't an interesting example
$tag1 = new Tag();
$tag1->name = 'tag1';
$tag1->setName('tag1');
$task->getTags()->add($tag1);
$tag2 = new Tag();
$tag2->name = 'tag2';
$tag2->setName('tag2');
$task->getTags()->add($tag2);
// end dummy code

Expand Down