1

Symfony 5.4, php7.4.

After removing sensio/framework-extra-bundle, as it is abandoned, all routes which contain ids returns an error message:

Cannot autowire argument $user of "App\Controller\Back\UserController::read()": it references class "App\Entity\User" but no such service exists.

Controller:

use Symfony\Component\Routing\Annotation\Route;

     
/**      
* @Route("/{id}", name="read", requirements={"id"="\d+"}, methods={"GET"})      
*/     
public function read(User $user): Response     
{         return $this->render('back/user/read.html.twig', [
             'user' => $user,         ]);     
}
My services.yaml:
services:
     _defaults:
         autowire: true         
         autoconfigure: true

App\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php' 

As it is stated here, this budnle included config for annotations and paramConverter, so I suppose my routes don't work now cause ids cannot be converted.

So should I install any other bundle instead sensio-extra-bundle to make my routes work or I need to change something in my annotations?

Thanks for help.

svitb
  • 11
  • 1

1 Answers1

0

I don't find any Symfony paramConverter package that works like abandoned frameworkExtraBundle.

My basic solution for my little app is find Entity into Controller:

/**      
* @Route("/{id}", name="read", requirements={"id"="\d+"}, methods={"GET"})      
*/     
public function read(int $user): Response     
{     
   $user = $this->em->getRepository(User::class)->find($user);

   return $this->render('back/user/read.html.twig', [
             'user' => $user,         ]);     
}
Sanloja
  • 1
  • 1