@@ -209,9 +209,9 @@ inside the ``Entity`` directory of your AppBundle::
209
209
210
210
class Product
211
211
{
212
- protected $name;
213
- protected $price;
214
- protected $description;
212
+ private $name;
213
+ private $price;
214
+ private $description;
215
215
}
216
216
217
217
The class - often called an "entity", meaning *a basic class that holds data * -
@@ -274,22 +274,22 @@ directly inside the ``Product`` class via DocBlock annotations:
274
274
* @ORM\Id
275
275
* @ORM\GeneratedValue(strategy="AUTO")
276
276
*/
277
- protected $id;
277
+ private $id;
278
278
279
279
/**
280
280
* @ORM\Column(type="string", length=100)
281
281
*/
282
- protected $name;
282
+ private $name;
283
283
284
284
/**
285
285
* @ORM\Column(type="decimal", scale=2)
286
286
*/
287
- protected $price;
287
+ private $price;
288
288
289
289
/**
290
290
* @ORM\Column(type="text")
291
291
*/
292
- protected $description;
292
+ private $description;
293
293
}
294
294
295
295
.. code-block :: yaml
@@ -391,10 +391,10 @@ Generating Getters and Setters
391
391
392
392
Even though Doctrine now knows how to persist a ``Product `` object to the
393
393
database, the class itself isn't really useful yet. Since ``Product `` is just
394
- a regular PHP class with ``protected `` properties, you need to create ``public ``
394
+ a regular PHP class with ``private `` properties, you need to create ``public ``
395
395
getter and setter methods (e.g. ``getName() ``, ``setName($name) ``) in order
396
- to access its properties. Fortunately, the following command can generate
397
- these boilerplate methods automatically:
396
+ to access its properties in the rest of your application's code. Fortunately,
397
+ the following command can generate these boilerplate methods automatically:
398
398
399
399
.. code-block :: bash
400
400
@@ -444,13 +444,6 @@ mapping information) of a bundle or an entire namespace:
444
444
# generates all entities of bundles in the Acme namespace
445
445
$ php app/console doctrine:generate:entities Acme
446
446
447
- .. note ::
448
-
449
- Doctrine doesn't care whether your properties are ``protected `` or ``private ``,
450
- or whether corresponding getter/setter methods exist for your properties.
451
- Using getters and setters is suggested here only because you'll need them
452
- to interact with your PHP object in the rest of your application's code.
453
-
454
447
.. _book-doctrine-creating-the-database-tables-schema :
455
448
456
449
Creating the Database Tables/Schema
@@ -944,7 +937,7 @@ To relate the ``Category`` and ``Product`` entities, start by creating a
944
937
/**
945
938
* @ORM\OneToMany(targetEntity="Product", mappedBy="category")
946
939
*/
947
- protected $products;
940
+ private $products;
948
941
949
942
public function __construct()
950
943
{
@@ -1027,7 +1020,7 @@ object, you'll want to add a ``$category`` property to the ``Product`` class:
1027
1020
* @ORM\ManyToOne(targetEntity="Category", inversedBy="products")
1028
1021
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
1029
1022
*/
1030
- protected $category;
1023
+ private $category;
1031
1024
}
1032
1025
1033
1026
.. code-block :: yaml
0 commit comments