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