<?php
namespace App\Controller;
use App\Repository\CategoryRepository;
use Doctrine\ORM\PersistentCollection;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class CategoryController extends AbstractController
{
/**
* @Route("/category/{slug}", name="category")
*/
public function index(Request $request, CategoryRepository $categoryRepository): Response
{
$slug = $request->attributes->get('slug');
/** @var PersistentCollection $products */
$products = $categoryRepository->findOneBy(['slug' => $slug])->getProducts()->toArray();
return $this->render('category/index.html.twig', [
'controller_name' => 'CategoryController',
'slides' => array_chunk($categoryRepository->findAll(), 4),
'products' => $products,
]);
}
}