Skip to content

Commit

Permalink
Merge branch '4.4' into 5.0
Browse files Browse the repository at this point in the history
* 4.4:
  Getting product using Symfony autowiring
  • Loading branch information
javiereguiluz committed Jan 2, 2020
2 parents b9a1847 + 711b4b0 commit cb9ad70
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,24 @@ be able to go to ``/product/1`` to see your new product::
// in the template, print things with {{ product.name }}
// return $this->render('product/show.html.twig', ['product' => $product]);
}
Another possibility is to use the ``ProductRepository`` using Symfony's autowiring
and injected by the dependency injection container::

// src/Controller/ProductController.php
// ...
use App\Repository\ProductRepository;

/**
* @Route("/product/{id}", name="product_show")
*/
public function show($id, ProductRepository $productRepository)
{
$product = $productRepository
->find($id);
// ...
}

Try it out!

Expand Down

0 comments on commit cb9ad70

Please sign in to comment.