<?php
namespace App\Controller;
use Faker\Factory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class ArticleController extends AbstractController
{
#[Route('/article', name: 'app_article_list', methods: ['GET'])]
public function index(): Response
{
$faker = Factory::create('fr_FR');
$articles = [];
for ($i = 0; $i < 10; $i++) {
$article = [
'image' => 'https://picsum.photos/640/480',
'title' => $faker->sentence,
'content' => $faker->paragraph,
'slug' => $faker->slug
];
$articles[] = $article;
}
return $this->render('article/index.html.twig', [
'articles' => $articles,
]);
}
#[Route('/article/{slug}', name: 'app_article_show', methods: ['GET'])]
public function show(string $slug): Response
{
$faker = Factory::create('fr_FR');
return $this->render('article/show.html.twig', [
'article' => [
'image' => 'https://picsum.photos/1280/600',
'title' => $faker->sentence,
'content' => $faker->paragraphs(4),
]
]);
}
}