Skip to content

Commit cb9ad70

Browse files
committed
Merge branch '4.4' into 5.0
* 4.4: Getting product using Symfony autowiring
2 parents b9a1847 + 711b4b0 commit cb9ad70

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

doctrine.rst

+18
Original file line numberDiff line numberDiff 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

522540
Try it out!
523541

0 commit comments

Comments
 (0)