src/Controller/ShopController.php line 28
<?php
namespace App\Controller;
use App\Entity\Product;
use App\Entity\Image;
use App\Repository\ProductRepository;
use App\Repository\ImageRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class ShopController extends AbstractController
{
private $ProductRepository;
private $ImageRepository;
public function __construct(ProductRepository $ProductRepo, ImageRepository $ImageRepo)
{
$this->ProductRepository = $ProductRepo;
$this->ImageRepository = $ImageRepo;
}
#[Route('/shop', name: 'shop')]
public function index(Request $request)
{
$products = $this->ProductRepository->findAllOnline();
return $this->render('shop/index.html.twig', [
'products' => $products
]);
}
#[Route('/shop/product/{id}', name: 'shop_product')]
public function show(Request $request, int $id)
{
$product = $this->ProductRepository->findOneById($id);
$images = $this->ImageRepository->findImagesByProduct($product);
return $this->render('shop/product.html.twig', [
'product' => $product,
'product_images' => $images,
]);
}
}