@@ -640,34 +640,6 @@ automatically! You can simplify the controller to::
640640That's it! The bundle uses the ``{id} `` from the route to query for the ``Product ``
641641by the ``id `` column. If it's not found, a 404 page is generated.
642642
643- This behavior is enabled by default on all your controllers. You can
644- disable it by setting the ``doctrine.orm.controller_resolver.auto_mapping ``
645- config option to ``false ``.
646-
647- When disabled, you can enable it individually on the desired controllers by
648- using the ``MapEntity `` attribute::
649-
650- // src/Controller/ProductController.php
651- namespace App\Controller;
652-
653- use App\Entity\Product;
654- use Symfony\Bridge\Doctrine\Attribute\MapEntity;
655- use Symfony\Component\HttpFoundation\Response;
656- use Symfony\Component\Routing\Annotation\Route;
657- // ...
658-
659- class ProductController extends AbstractController
660- {
661- #[Route('/product/{id}')]
662- public function show(
663- #[MapEntity]
664- Product $product
665- ): Response {
666- // use the Product!
667- // ...
668- }
669- }
670-
671643.. tip ::
672644
673645 When enabled globally, it's possible to disable the behavior on a specific
@@ -713,14 +685,41 @@ Automatic fetching works in these situations:
713685 *all * of the wildcards in your route that are actually properties
714686 on your entity (non-properties are ignored).
715687
716- You can control this behavior by actually *adding * the ``MapEntity ``
717- attribute and using the `MapEntity options `_.
688+ This behavior is enabled by default on all controllers. If you prefer, you can
689+ restrict this feature to only work on route wildcards called ``id `` to look for
690+ entities by primary key. To do so, set the option
691+ ``doctrine.orm.controller_resolver.auto_mapping `` to ``false ``.
692+
693+ When ``auto_mapping `` is disabled, you can configure the mapping explicitly for
694+ any controller argument with the ``MapEntity `` attribute. You can even control
695+ the ``EntityValueResolver `` behavior by using the `MapEntity options `_ ::
696+
697+ // src/Controller/ProductController.php
698+ namespace App\Controller;
699+
700+ use App\Entity\Product;
701+ use Symfony\Bridge\Doctrine\Attribute\MapEntity;
702+ use Symfony\Component\HttpFoundation\Response;
703+ use Symfony\Component\Routing\Annotation\Route;
704+ // ...
705+
706+ class ProductController extends AbstractController
707+ {
708+ #[Route('/product/{slug}')]
709+ public function show(
710+ #[MapEntity(mapping: ['slug' => 'slug'])]
711+ Product $product
712+ ): Response {
713+ // use the Product!
714+ // ...
715+ }
716+ }
718717
719718Fetch via an Expression
720719~~~~~~~~~~~~~~~~~~~~~~~
721720
722- If automatic fetching doesn't work, you can write an expression using the
723- :doc: `ExpressionLanguage component </components/expression_language >`::
721+ If automatic fetching doesn't work for your use case , you can write an expression
722+ using the :doc: `ExpressionLanguage component </components/expression_language >`::
724723
725724 #[Route('/product/{product_id}')]
726725 public function show(
0 commit comments