Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1b92a9f

Browse filesBrowse files
abdounikarimjaviereguiluz
authored andcommitted
Getting product using Symfony autowiring
1 parent 0106fc9 commit 1b92a9f
Copy full SHA for 1b92a9f

File tree

Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed

‎doctrine.rst

Copy file name to clipboardExpand all lines: doctrine.rst
+18Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.