0

I just started to learn symfony 4.2 and following symfony official documentation site. My Controller looks like

<?php

// src/Controller/LuckyController.php
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class LuckyController
{
    /**
     * @Route("/lucky/number/{max}")
      */
    public function number($max)
    {
        $number = random_int(0, $max);

        return new Response(
            '<html><body>Lucky number: '.$number.'</body></html>'
        );
    }
}

?>

and my URL is http://localhost:8012/symfony/public/lucky/number/10. Annotation is not working here because when I call this on browser I am getting 404 error.

  • You forgot the slug. Read the documentation - https://symfony.com/doc/current/routing.html. Like this - `@Route("/lucky/number/{max}")` – Sumit Wadhwa Mar 16 '19 at 05:23
  • @kenzotenma thank you ..i just updated the code still getting same error . –  Mar 16 '19 at 05:30
  • there is a slight indentation on the third line of your annotation. fix that and try again. – Sumit Wadhwa Mar 16 '19 at 05:50
  • @kenzotenma sorry i dont get u ..could you explain ? –  Mar 16 '19 at 06:01
  • the route annotation - on the third line. there's an extra space there. fix that and try again. refer to the docs and make sure your annotation comment looks exactly alike – Sumit Wadhwa Mar 16 '19 at 06:23

0 Answers0