src/Controller/CategoryController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\ArticleRepository;
  4. use App\Repository\CategoryRepository;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. class CategoryController extends AbstractController
  9. {
  10.     private $articleRepository;
  11.     private $categoryRepository;
  12.     public  function __construct(ArticleRepository $articleRepositoryCategoryRepository $categoryRepository)
  13.     {
  14.         $this->categoryRepository $categoryRepository;
  15.         $this->articleRepository $articleRepository;
  16.     }
  17.     /**
  18.      *
  19.      * @Route("/category/{id}", name="app_category")
  20.      */
  21.     public function index($id): Response
  22.     {
  23.         $articles $this->articleRepository->findBy(array('category' => $id));
  24.         $category $this->categoryRepository->findOneBy(['id' => $id]);
  25.         return $this->render('category/index.html.twig', [
  26.             'articles' => $articles,
  27.             'category' => $category
  28.         ]);
  29.     }
  30. }