src/Controller/NewsController.php line 65

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  6. /**
  7.  * @Route("/news", priority=10, name="news_")
  8.  */
  9. class NewsController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/", name="index")
  13.      */
  14.     public function index()
  15.     {
  16.         /* Get news from api */
  17.         $newsJson = ['entries' => []];
  18.         try {
  19.             $newsJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/news?token=863f1ccdb97de3b924e07b600ce0f5');
  20.             if ($newsJsonPath !== false) {
  21.                 $newsJson json_decode($newsJsonPathtrue) ?: ['entries' => []];
  22.             }
  23.         } catch (\Exception $e) {
  24.             error_log('API Error in NewsController (news): ' $e->getMessage());
  25.         }
  26.         /* Get meta from api */
  27.         $metaJson null;
  28.         try {
  29.             $metaJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/singletons/get/news?token=863f1ccdb97de3b924e07b600ce0f5');
  30.             if ($metaJsonPath !== false) {
  31.                 $metaJson json_decode($metaJsonPathtrue);
  32.             }
  33.         } catch (\Exception $e) {
  34.             error_log('API Error in NewsController (meta): ' $e->getMessage());
  35.         }
  36.         
  37.         // Fallback if API is not available
  38.         if ($metaJson === null) {
  39.             $metaJson = [
  40.                 'title' => 'News',
  41.                 'description' => 'Alle Neuigkeiten rund um den Tennis Club.',
  42.                 'keywords' => 'Tennis, News, CTC, Rheda'
  43.             ];
  44.         }
  45.         return $this->render('pages/news.html.twig', [
  46.             // passed data to template
  47.             'news' => $newsJson['entries'],
  48.             'page' => array(
  49.                 'title' => 'News',
  50.                 'description' => 'Alle Neuigkeiten rund um den Tennis Club.',
  51.                 'meta' => $metaJson
  52.             )
  53.         ]);
  54.     }
  55.     /**
  56.      * @Route("/{slug}", name="detail")
  57.      */
  58.     public function detail($slug)
  59.     {
  60.         /* Get news from api */
  61.         $newsJson = ['entries' => []];
  62.         try {
  63.             $newsJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/news?token=863f1ccdb97de3b924e07b600ce0f5');
  64.             if ($newsJsonPath !== false) {
  65.                 $newsJson json_decode($newsJsonPathtrue) ?: ['entries' => []];
  66.             }
  67.         } catch (\Exception $e) {
  68.             error_log('API Error in NewsController detail (news): ' $e->getMessage());
  69.         }
  70.         return $this->render('pages/news-detail.html.twig', [
  71.             // passed data to template
  72.             'slug' => $slug,
  73.             'news' => $newsJson['entries'],
  74.         ]);
  75.     }
  76. }