src/Controller/PicturesViewController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\AlbumRepository;
  4. use App\Repository\PicturesRepository;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class PicturesViewController extends AbstractController
  10. {
  11.     private $entitymanager;
  12.     public function __construct(EntityManagerInterface $entityManagerInterface)
  13.     {
  14.         return $this->entitymanager $entityManagerInterface;
  15.     }
  16.     // VOIR LES PHOTOS
  17.     #[Route('/album/{id}'name'pictures_album')]
  18.     public function index(PicturesRepository $picturesRepository$idAlbumRepository $albumRepository): Response
  19.     {
  20.         $album $albumRepository->findOneById($id);
  21.         $pictures $picturesRepository->findPictures($id);
  22.         return $this->render('pictures_view/index.html.twig', [
  23.             'pictures' => $pictures,
  24.             'album' => $album
  25.         ]);
  26.     }
  27.     // SUPPRIMER UNE PHOTO
  28.     #[Route('/album/delete/{id}'name'pictures_delete')]
  29.     public function delete(PicturesRepository $picturesRepository$id): Response
  30.     {
  31.         $photo $picturesRepository->findOneById($id);
  32.         $album $photo->getAlbum();
  33.         $this->entitymanager->remove($photo);
  34.         $this->entitymanager->flush();
  35.         $this->addFlash('success''Photo supprimée avec succès');
  36.         return $this->redirectToRoute('picture_dashboard', ['id' => $album->getId()]);
  37.     }
  38. }