src/Controller/Blocks/BestProductsController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Blocks;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use App\Repository\ProductRepository;
  7. use App\Repository\CategoryRepository;
  8. class BestProductsController extends AbstractController
  9. {
  10.     private $productRepository;
  11.     private $categoryRepository;
  12.     public function __construct(
  13.         ProductRepository $productRepository,
  14.         CategoryRepository $categoryRepository
  15.     )
  16.     {
  17.         $this->productRepository $productRepository;
  18.         $this->categoryRepository $categoryRepository;
  19.     }
  20.     #[Route('/best/products'name'app_best_products')]
  21.     public function index(): Response
  22.     {
  23.         $categoryBestProducts $this->categoryRepository->findOneBy(["id" => 1]);
  24.         $products $categoryBestProducts->getProducts() ? $categoryBestProducts->getProducts() : [];
  25.         return $this->render('blocks/best_products/index.html.twig', [
  26.             'controller_name' => 'BestProductsController',
  27.             'products' => $products
  28.         ]);
  29.     }
  30. }