src/Controller/ContenidosLibresController.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use App\Entity\Curso;
  9. use App\Entity\Categoria;
  10. use App\Entity\Album;
  11. class ContenidosLibresController extends AbstractController
  12. {
  13.     private $entityManager;
  14.     private $cursoRepository;
  15.     private $categoriaRepository;
  16.     private $albumRepository;
  17.     public function __construct(EntityManagerInterface $entityManagerParameterBagInterface $parameterBag)
  18.     {
  19.         //Doctrine
  20.         $this->entityManager $entityManager;
  21.         $this->cursoRepository $this->entityManager->getRepository(Curso::class);
  22.         $this->categoriaRepository $this->entityManager->getRepository(Categoria::class);
  23.         $this->albumRepository $this->entityManager->getRepository(Album::class);
  24.     }
  25.     /**
  26.      * @Route("/contenidosLibres/home", name="app_contenidosLibres" , methods={"GET","HEAD","POST"})
  27.      */
  28.     public function index(): Response
  29.     {
  30.         //Obtengo todos los cursos para mostrar
  31.         $cursos $this->cursoRepository->findByCursosPublicos();
  32.         $categoriasCursos $this->categoriaRepository->findByCategoriasCursos();
  33.         //Obtengo todos los albums para mostrar
  34.         $albums $this->albumRepository->findByActivos();
  35.         //Retorno a la vista
  36.         return $this->render(
  37.             'ContenidosLibres/index.html.twig',
  38.             [
  39.                 'cursos' => $cursos,
  40.                 'categorias' => $categoriasCursos,
  41.                 'albums' => $albums
  42.             ]
  43.         );
  44.     }
  45. }