<?php
namespace App\Controller;
use App\Repository\AlbumRepository;
use App\Repository\CategoryRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class AlbumViewController extends AbstractController
{
private $entitymanager;
public function __construct(EntityManagerInterface $entitymanager)
{
$this->entitymanager = $entitymanager;
}
// VOIR LES ALBUMS
#[Route('/categorie/{id}', name: 'album_category')]
public function index(AlbumRepository $albumRepository, $id, CategoryRepository $categoryRepository): Response
{
$category = $categoryRepository->findOneById($id);
$album = $albumRepository->findAlbum($id);
return $this->render('album_view/index.html.twig', [
'albums' => $album,
'category' => $category
]);
}
// SUPPRIMER UN ALBUM
#[Route('/categorie/delete/{id}', name: 'albumview_delete')]
public function delete(AlbumRepository $albumRepository, $id, Request $request): Response
{
$album = $albumRepository->findOneById($id);
$category = $album->getCategory();
$this->entitymanager->remove($album);
$this->entitymanager->flush();
return $this->redirectToRoute('album_category', ['id' => $category->getId()]);
}
}