|
@@ -3,6 +3,7 @@
|
|
|
namespace App\Controller;
|
|
|
|
|
|
use App\Entity\Product;
|
|
|
+use App\Repository\ProductRepository;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
@@ -22,9 +23,9 @@ class ProductController extends Controller
|
|
|
*
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
|
*/
|
|
|
- public function index(EntityManagerInterface $em) {
|
|
|
- $repository = $em->getRepository(Product::class);
|
|
|
- $products = $repository->findAll();
|
|
|
+ public function index(ProductRepository $repository) {
|
|
|
+
|
|
|
+ $products = $repository->findProductsLessThan(21);
|
|
|
return $this->render('product/index.html.twig', ['products' => $products]);
|
|
|
}
|
|
|
|
|
@@ -82,11 +83,6 @@ class ProductController extends Controller
|
|
|
return $accu . '/' . $product->getId() . ' ' . $product->getName() . ': ' . $product->getDescription();
|
|
|
}, ''));
|
|
|
|
|
|
- $productsAll = $repository->findAll();
|
|
|
- $this->addFlash('error', array_reduce($productsAll, function (string $accu, Product $product) {
|
|
|
- return $accu . '/' . $product->getId() . ' ' . $product->getName() . ': ' . $product->getDescription();
|
|
|
- }, ''));
|
|
|
-
|
|
|
if (!$product) {
|
|
|
throw $this->createNotFoundException(
|
|
|
"No product found for id $id"
|