Skip to content

Commit 711b4b0

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: Getting product using Symfony autowiring
2 parents fef770b + be03e31 commit 711b4b0

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
@@ -522,6 +522,24 @@ be able to go to ``/product/1`` to see your new product::
522522
// in the template, print things with {{ product.name }}
523523
// return $this->render('product/show.html.twig', ['product' => $product]);
524524
}
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+
}
525543

526544
Try it out!
527545

0 commit comments

Comments
 (0)