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 be03e31

Browse filesBrowse files
committed
minor #12456 Getting product using Symfony autowiring (abdounikarim)
This PR was squashed before being merged into the 4.3 branch (closes #12456). Discussion ---------- Getting product using Symfony autowiring Hello, I add a code block to get product using Symfony autowiring and DependencyInjection. Do you think it's useful ? Cheers 😉 <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 1b92a9f Getting product using Symfony autowiring
2 parents c9dc31a + 1b92a9f commit be03e31
Copy full SHA for be03e31

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.