Skip to content

Commit 0f3f2ac

Browse files
committed
attribute routes
1 parent bfe3f45 commit 0f3f2ac

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

doctrine.rst

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ If you want to use XML instead of annotations, add ``type: xml`` and
210210
Be careful not to use reserved SQL keywords as your table or column names
211211
(e.g. ``GROUP`` or ``USER``). See Doctrine's `Reserved SQL keywords documentation`_
212212
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.
215215

216216
.. _doctrine-creating-the-database-tables-schema:
217217

@@ -288,9 +288,7 @@ methods:
288288
{
289289
// ...
290290
291-
+ /**
292-
+ * @ORM\Column(type="text")
293-
+ */
291+
+ #[ORM\Column(type: "text")];
294292
+ private $description;
295293
296294
// getDescription() & setDescription() were also added
@@ -359,12 +357,11 @@ and save it::
359357
use App\Entity\Product;
360358
use Doctrine\Persistence\ManagerRegistry;
361359
use Symfony\Component\HttpFoundation\Response;
360+
use Symfony\Component\Routing\Annotation\Route;
362361

363362
class ProductController extends AbstractController
364363
{
365-
/**
366-
* @Route("/product", name="create_product")
367-
*/
364+
#[Route('/product', name: 'create_product')
368365
public function createProduct(ManagerRegistry $doctrine): Response
369366
{
370367
$entityManager = $doctrine->getManager();
@@ -444,13 +441,12 @@ some basic validation tasks::
444441
use App\Entity\Product;
445442
use Symfony\Component\HttpFoundation\Response;
446443
use Symfony\Component\Validator\Validator\ValidatorInterface;
444+
use Symfony\Component\Routing\Annotation\Route;
447445
// ...
448446

449447
class ProductController extends AbstractController
450448
{
451-
/**
452-
* @Route("/product", name="create_product")
453-
*/
449+
#[Route('/product', name: 'create_product')
454450
public function createProduct(ValidatorInterface $validator): Response
455451
{
456452
$product = new Product();
@@ -513,9 +509,7 @@ be able to go to ``/product/1`` to see your new product::
513509

514510
class ProductController extends AbstractController
515511
{
516-
/**
517-
* @Route("/product/{id}", name="product_show")
518-
*/
512+
#[Route('/product/{id}', name: 'product_show')]
519513
public function show(ManagerRegistry $doctrine, int $id): Response
520514
{
521515
$product = $doctrine->getRepository(Product::class)->find($id);
@@ -547,9 +541,7 @@ and injected by the dependency injection container::
547541

548542
class ProductController extends AbstractController
549543
{
550-
/**
551-
* @Route("/product/{id}", name="product_show")
552-
*/
544+
#[Route('/product/{id}', name: 'product_show')]
553545
public function show(int $id, ProductRepository $productRepository): Response
554546
{
555547
$product = $productRepository
@@ -631,9 +623,7 @@ Now, simplify your controller::
631623

632624
class ProductController extends AbstractController
633625
{
634-
/**
635-
* @Route("/product/{id}", name="product_show")
636-
*/
626+
#[Route('/product/{id}', name: 'product_show')]
637627
public function show(Product $product): Response
638628
{
639629
// use the Product!
@@ -662,9 +652,7 @@ with any PHP model::
662652

663653
class ProductController extends AbstractController
664654
{
665-
/**
666-
* @Route("/product/edit/{id}")
667-
*/
655+
#[Route('/product/edit/{id}', name: 'product_edit')]
668656
public function update(ManagerRegistry $doctrine, int $id): Response
669657
{
670658
$entityManager = $doctrine->getManager();

0 commit comments

Comments
 (0)