Symfony4: No route found for "GET /lucky/number"

11,004

Solution 1

In Symfony4 you have to install annotations bundle.

Run this command composer require annotations

Then restart Your project.

Solution 2

Sometimes this problem occurs because of cache.you need to run php bin/console cache:clear.then it will work fine.

Solution 3

I had the same thing when trying the annotations, then I found out with the demo installed (the blog) you need to add the language in the URL. So the documentation says:

http://localhost:8000/lucky/number will work exactly like before

That did not work. This however did:

http://localhost:8000/en/lucky/number
Share:
11,004
sensorario
Author by

sensorario

The winter is coming.

Updated on June 23, 2022

Comments

  • sensorario
    sensorario almost 2 years

    I am starting to play with symfony4. I've just created new application and create new LuckyController. It works with routes.yaml configured in this manner:

    lucky:
        path: /lucky/number
        controller: App\Controller\LuckyController::number
    

    With the following controller:

    <?php
    
    namespace App\Controller;
    
    use Symfony\Component\HttpFoundation\Response;
    
    class LuckyController
    {
        public function number()
        {
            return new Response('<html><head></head><body>' . rand(111, 999) . '</body></html>');
        }
    }
    

    But I want to use annotations. So I decided to comment routes.yaml. Following documentation that explain how to create a route in symfony I've made this:

    <?php
    
    namespace App\Controller;
    
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Routing\Annotation\Route;
    
    class LuckyController extends Controller
    {
        /**
         * @Route("/lucky/number")
         */
        public function number()
        {
            return new Response('<html><head></head><body>' . rand(111, 999) . '</body></html>');
        }
    }
    

    No route found