src/Controller/ShopController.php line 28

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Product;
  4. use App\Entity\Image;
  5. use App\Repository\ProductRepository;
  6. use App\Repository\ImageRepository;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. class ShopController extends AbstractController
  12. {
  13.     private $ProductRepository;
  14.     private $ImageRepository;
  15.     public function __construct(ProductRepository $ProductRepoImageRepository $ImageRepo)
  16.     {
  17.         $this->ProductRepository $ProductRepo;
  18.         $this->ImageRepository $ImageRepo;
  19.     }
  20.     #[Route('/shop'name'shop')]
  21.     public function index(Request $request)
  22.     {
  23.         $products $this->ProductRepository->findAllOnline();
  24.         return $this->render('shop/index.html.twig', [
  25.             'products' => $products
  26.         ]);
  27.     }
  28.     #[Route('/shop/product/{id}'name'shop_product')]
  29.     public function show(Request $requestint $id)
  30.     {
  31.         $product $this->ProductRepository->findOneById($id);
  32.         $images $this->ImageRepository->findImagesByProduct($product);
  33.         return $this->render('shop/product.html.twig', [
  34.             'product' => $product,
  35.             'product_images' => $images,
  36.         ]);
  37.     }
  38. }