File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Original file line number Diff line number Diff line change @@ -522,6 +522,24 @@ be able to go to ``/product/1`` to see your new product::
522
522
// in the template, print things with {{ product.name }}
523
523
// return $this->render('product/show.html.twig', ['product' => $product]);
524
524
}
525
+
526
+ Another possibility is to use the ``ProductRepository `` using Symfony's autowiring
527
+ and injected by the dependency injection container::
528
+
529
+ // src/Controller/ProductController.php
530
+ // ...
531
+ use App\Repository\ProductRepository;
532
+
533
+ /**
534
+ * @Route("/product/{id}", name="product_show")
535
+ */
536
+ public function show($id, ProductRepository $productRepository)
537
+ {
538
+ $product = $productRepository
539
+ ->find($id);
540
+
541
+ // ...
542
+ }
525
543
526
544
Try it out!
527
545
You can’t perform that action at this time.
0 commit comments