src/Controller/ArticleController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Faker\Factory;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class ArticleController extends AbstractController
  8. {
  9.     #[Route('/article'name'app_article_list'methods: ['GET'])]
  10.     public function index(): Response
  11.     {
  12.         $faker Factory::create('fr_FR');
  13.         $articles = [];
  14.         for ($i 0$i 10$i++) {
  15.             $article = [
  16.               'image' => 'https://picsum.photos/640/480',
  17.               'title' => $faker->sentence,
  18.               'content' => $faker->paragraph,
  19.                 'slug' => $faker->slug
  20.             ];
  21.             $articles[] = $article;
  22.         }
  23.         return $this->render('article/index.html.twig', [
  24.             'articles' => $articles,
  25.         ]);
  26.     }
  27.     #[Route('/article/{slug}'name'app_article_show'methods: ['GET'])]
  28.     public function show(string $slug): Response
  29.     {
  30.         $faker Factory::create('fr_FR');
  31.         return $this->render('article/show.html.twig', [
  32.             'article' => [
  33.                 'image' => 'https://picsum.photos/1280/600',
  34.                 'title' => $faker->sentence,
  35.                 'content' => $faker->paragraphs(4),
  36.             ]
  37.         ]);
  38.     }
  39. }