@@ -639,34 +639,6 @@ automatically! You can simplify the controller to::
639
639
That's it! The bundle uses the ``{id} `` from the route to query for the ``Product ``
640
640
by the ``id `` column. If it's not found, a 404 page is generated.
641
641
642
- This behavior is enabled by default on all your controllers. You can
643
- disable it by setting the ``doctrine.orm.controller_resolver.auto_mapping ``
644
- config option to ``false ``.
645
-
646
- When disabled, you can enable it individually on the desired controllers by
647
- using the ``MapEntity `` attribute::
648
-
649
- // src/Controller/ProductController.php
650
- namespace App\Controller;
651
-
652
- use App\Entity\Product;
653
- use Symfony\Bridge\Doctrine\Attribute\MapEntity;
654
- use Symfony\Component\HttpFoundation\Response;
655
- use Symfony\Component\Routing\Annotation\Route;
656
- // ...
657
-
658
- class ProductController extends AbstractController
659
- {
660
- #[Route('/product/{id}')]
661
- public function show(
662
- #[MapEntity]
663
- Product $product
664
- ): Response {
665
- // use the Product!
666
- // ...
667
- }
668
- }
669
-
670
642
.. tip ::
671
643
672
644
When enabled globally, it's possible to disable the behavior on a specific
@@ -712,8 +684,37 @@ Automatic fetching works in these situations:
712
684
*all * of the wildcards in your route that are actually properties
713
685
on your entity (non-properties are ignored).
714
686
715
- You can control this behavior by actually *adding * the ``MapEntity ``
716
- attribute and using the `MapEntity options `_.
687
+ This behavior is enabled by default on all your controllers.
688
+
689
+ You can only allow the use of the primary key as a lookup placeholder ``id `` on the route
690
+ by setting the ``doctrine.orm.controller_resolver.auto_mapping `` config option to ``false ``.
691
+ The other attribute will not be used to autowire the entity.
692
+
693
+ When disabled, you can enable it individually on the desired controllers by
694
+ using the ``MapEntity `` attribute. You can control `EntityValueResolver ` behavior
695
+ with it 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
+ }
717
+
717
718
718
719
Fetch via an Expression
719
720
~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments