flex: [Bug] Can't load routing via annotations

If I uncomment this in the default /etc/routing.yaml:

controllers:
    resource: ../src/Controller/
    type: annotation

And create a src/Controller/DefaultController.php with the appropriate annotations, I see this error:

error-routing-annotations


But this should work after this change: https://github.com/symfony/symfony/pull/21231

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 19 (11 by maintainers)

Most upvoted comments

@AxelBriche, in my case I had forgotten the .htaccess, which is not created by default with symfony/flex. Posted a complete answer here: https://stackoverflow.com/a/49209861/2761700

@darius-v composer req annotations

I created a pr to the docs to add the install line.

Hello, I have this error:

The requested URL /message was not found on this server.

composer req annotations

annotations.yaml

controllers:
    resource: ../../src/Controller/
    type: annotation

routes.yaml

#index:
#    path: /
#    controller: App\Controller\MessageController::index

MessageController.php

<?php

namespace App\Controller;

use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class MessageController extends Controller
{
    /**
     * @Route("/message", name="message")
     */
    public function index()
    {
        return $this->render('message/index.html.twig', [
            'controller_name' => 'MessageController',
        ]);
    }
}

php bin/console debug:router show the route:

Name Method Scheme Host Path
message ANY ANY ANY /message

But the route /message doesn’t work.

Another routing problem:

"An error occurred while loading the web debug toolbar"
"The requested URL /_profiler/4029fd was not found on this server."

Note: It’s a clean new Flex installation, I have followed the official doc. Note2: I have run: composer require sensio/framework-extra-bundle, already installed.