Skip to content

Commit e02f7d0

Browse files
committed
Merge branch '5.0'
* 5.0: Getting product using Symfony autowiring
2 parents affd94a + cb9ad70 commit e02f7d0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

doctrine.rst

Lines changed: 18 additions & 0 deletions
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)