src/Controller/HelloController.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. class HelloController extends AbstractController
  7. {
  8.     private array $messages = [
  9.         ['message' => 'Hello''created' => '2022/12/01'],
  10.         ['message' => 'Hi''created' => '2022/10/12'],
  11.         ['message' => 'Bye!''created' => '2021/05/12']
  12.     ];
  13.     #[Route('/{limit<\d+>?3}'name'app_index')]
  14.     public function index(int $limit): Response
  15.     {
  16.         return $this->render(
  17.             'hello/index.html.twig',
  18.             [
  19.                 'messages' => $this->messages,
  20.                 'limit' => $limit
  21.             ]
  22.         );
  23.     }
  24.     #[Route('/messages/{id<\d+>}'name'app_show_one')]
  25.     public function showOne(int $id): Response
  26.     {
  27.         return $this->render(
  28.             'hello/show_one.html.twig',
  29.             [
  30.                 'message' => $this->messages[$id]
  31.             ]
  32.         );
  33.     }
  34. }