src/Controller/Mvc/NewsController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Mvc;
  3. use App\Entity\Interfaces\Cms\LinkInterface;
  4. use App\Repository\News\CategoryRepository;
  5. use App\Service\Entity\News\EntryService;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. #[Route(path"/news")]
  11. class NewsController extends AbstractController
  12. {
  13.     #[Route(path"/"name"news_index"methods: ["GET"])]
  14.     public function index(
  15.         Request $request,
  16.         CategoryRepository $categoryRepository,
  17.         EntryService $service
  18.     ): Response
  19.     {
  20.         $service->setContainer($this->container);
  21.         $paginate $service->getPagination($request7);
  22.         return $this->render("pages/news/index.html.twig", [
  23.             "paginate" => $paginate,
  24.             "categories" => $categoryRepository->getCategoriesHaveEntry()
  25.         ]);
  26.     }
  27.     
  28.     #[Route(path"/{id}"name"news_detail"requirements: ["id" => "\d+"], methods: ["GET"])]
  29.     public function detail(
  30.         EntryService $entryService,
  31.         int $id
  32.     ): Response
  33.     {
  34.         $entry $entryService->getEntryById($id);
  35.         if(!$entry) {
  36.             throw $this->createNotFoundException();
  37.         }
  38.         if(
  39.             in_array(LinkInterface::class, class_implements($entry), true) &&
  40.             $entry->getLinkUrl()
  41.         ) {
  42.             return $this->redirect($entry->getLinkUrl());
  43.         }
  44.         return $this->render("pages/news/detail.html.twig" ,[
  45.             "entry" => $entry,
  46.             "ba" => $entryService->getBeforeAfter($entry)
  47.         ]);
  48.     }
  49.     
  50.     #[Route(path"/headline"name"news_headline"methods: ["GET"])]
  51.     public function headline(
  52.         Request $request,
  53.         EntryService $service
  54.     ): Response
  55.     {
  56.         $service->setContainer($this->container);
  57.         $paginate $service->getPagination($request3);
  58.         return $this->render("pages/news/headline.html.twig", [
  59.             "paginate" => $paginate
  60.         ]);
  61.     }
  62. }