src/Controller/actualiteController.php line 65

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Contracts\HttpClient\HttpClientInterface;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. class actualiteController extends AbstractController
  8. {
  9.     private $client;
  10.     public function __construct(HttpClientInterface $client)
  11.     {
  12.         $this->client $client;
  13.     }
  14.     
  15.     /**
  16.      * @Route("/actualite-de-l-audition")
  17.      */
  18.     public function renderActualitePage()
  19.     {
  20.         $response $this->client->request(
  21.             'GET',
  22.             "{$_ENV['BASE_API']}articles"
  23.         );
  24.         $content $response->toArray()["articles"];
  25. //dd($content);
  26.         return $this->render('./actualite/actualite.html.twig', array(
  27.             "articles" => json_encode($content),
  28.             "pro" => "false",
  29.             "base" => "base.html.twig"
  30.         ));
  31.         
  32.     }
  33.      /**
  34.      * @Route("/pro/actualite")
  35.      */
  36.     public function renderActualiteProPage()
  37.     {
  38.         $response $this->client->request(
  39.             'GET',
  40.             "{$_ENV['BASE_API']}articles/pro"
  41.         );
  42.         $content $response->toArray()["articles"];
  43.         return $this->render('./actualite/actualite.html.twig', array(
  44.             "articles" => json_encode($content),
  45.             "pro" => "true",
  46.             "base" => "/pro/base.html.twig"
  47.         ));
  48.         
  49.     }
  50.     /**
  51.      * @Route("/actualite-de-l-audition/{slug}")
  52.      */
  53.     public function renderArticlePage(string $slug)
  54.     {
  55.         $response $this->client->request(
  56.             'GET',
  57.             "{$_ENV['BASE_API']}article/".$slug
  58.         );
  59.         $content $response->toArray();
  60.         $category $this->client->request(
  61.             'GET',
  62.             "{$_ENV['BASE_API']}articles/categories/withArticle"
  63.         );
  64.         $response $this->client->request(
  65.             'GET',
  66.             "{$_ENV['BASE_API']}articles?limit=4"
  67.         );
  68.         $articles $response->toArray()["articles"];
  69.         
  70.         return $this->render('./actualite/article.html.twig', array(
  71.             "article" => $content,
  72.             "category" => $category->toArray()['content'],
  73.             "articles" => $articles,
  74.             "id" => $slug,
  75.             "pro" => "false",
  76.             "base" => "base.html.twig"
  77.         ));
  78.         
  79.     }
  80.     /**
  81.      * @Route("pro/actualite-de-l-audition/{slug}")
  82.      */
  83.     public function renderArticleProPage(string $slug)
  84.     {
  85.         $response $this->client->request(
  86.             'GET',
  87.             "{$_ENV['BASE_API']}article/".$slug
  88.         );
  89.         $content $response->toArray();
  90.         $category $this->client->request(
  91.             'GET',
  92.             "{$_ENV['BASE_API']}articles/pro/categories/withArticle"
  93.         );
  94.         $response $this->client->request(
  95.             'GET',
  96.             "{$_ENV['BASE_API']}articles/pro?limit=4"
  97.         );
  98.         $articles $response->toArray()["articles"];
  99.         
  100.         return $this->render('./actualite/article.html.twig', array(
  101.             "article" => $content,
  102.             "category" => $category->toArray()['content'],
  103.             "articles" => $articles,
  104.             "id" => $slug,
  105.             "pro" => "true",
  106.             "base" => "/pro/base.html.twig"
  107.         ));
  108.         
  109.     }
  110. }
  111. ?>