@@ -210,8 +210,8 @@ If you want to use XML instead of annotations, add ``type: xml`` and
210
210
Be careful not to use reserved SQL keywords as your table or column names
211
211
(e.g. ``GROUP `` or ``USER ``). See Doctrine's `Reserved SQL keywords documentation `_
212
212
for details on how to escape these. Or, change the table name with
213
- ``@ ORM\Table(name= "groups") `` above the class or configure the column name with
214
- the ``name= "group_name" `` option.
213
+ ``#[ ORM\Table(name: "groups")] `` above the class or configure the column name with
214
+ the ``name: "group_name" `` option.
215
215
216
216
.. _doctrine-creating-the-database-tables-schema :
217
217
@@ -288,9 +288,7 @@ methods:
288
288
{
289
289
// ...
290
290
291
- + /**
292
- + * @ORM\Column(type="text")
293
- + */
291
+ + #[ORM\Column(type: "text")];
294
292
+ private $description;
295
293
296
294
// getDescription() & setDescription() were also added
@@ -359,12 +357,11 @@ and save it::
359
357
use App\Entity\Product;
360
358
use Doctrine\Persistence\ManagerRegistry;
361
359
use Symfony\Component\HttpFoundation\Response;
360
+ use Symfony\Component\Routing\Annotation\Route;
362
361
363
362
class ProductController extends AbstractController
364
363
{
365
- /**
366
- * @Route("/product", name="create_product")
367
- */
364
+ #[Route('/product', name: 'create_product')
368
365
public function createProduct(ManagerRegistry $doctrine): Response
369
366
{
370
367
$entityManager = $doctrine->getManager();
@@ -444,13 +441,12 @@ some basic validation tasks::
444
441
use App\Entity\Product;
445
442
use Symfony\Component\HttpFoundation\Response;
446
443
use Symfony\Component\Validator\Validator\ValidatorInterface;
444
+ use Symfony\Component\Routing\Annotation\Route;
447
445
// ...
448
446
449
447
class ProductController extends AbstractController
450
448
{
451
- /**
452
- * @Route("/product", name="create_product")
453
- */
449
+ #[Route('/product', name: 'create_product')
454
450
public function createProduct(ValidatorInterface $validator): Response
455
451
{
456
452
$product = new Product();
@@ -513,9 +509,7 @@ be able to go to ``/product/1`` to see your new product::
513
509
514
510
class ProductController extends AbstractController
515
511
{
516
- /**
517
- * @Route("/product/{id}", name="product_show")
518
- */
512
+ #[Route('/product/{id}', name: 'product_show')]
519
513
public function show(ManagerRegistry $doctrine, int $id): Response
520
514
{
521
515
$product = $doctrine->getRepository(Product::class)->find($id);
@@ -547,9 +541,7 @@ and injected by the dependency injection container::
547
541
548
542
class ProductController extends AbstractController
549
543
{
550
- /**
551
- * @Route("/product/{id}", name="product_show")
552
- */
544
+ #[Route('/product/{id}', name: 'product_show')]
553
545
public function show(int $id, ProductRepository $productRepository): Response
554
546
{
555
547
$product = $productRepository
@@ -631,9 +623,7 @@ Now, simplify your controller::
631
623
632
624
class ProductController extends AbstractController
633
625
{
634
- /**
635
- * @Route("/product/{id}", name="product_show")
636
- */
626
+ #[Route('/product/{id}', name: 'product_show')]
637
627
public function show(Product $product): Response
638
628
{
639
629
// use the Product!
@@ -662,9 +652,7 @@ with any PHP model::
662
652
663
653
class ProductController extends AbstractController
664
654
{
665
- /**
666
- * @Route("/product/edit/{id}")
667
- */
655
+ #[Route('/product/edit/{id}', name: 'product_edit')]
668
656
public function update(ManagerRegistry $doctrine, int $id): Response
669
657
{
670
658
$entityManager = $doctrine->getManager();
0 commit comments