A simple but silly problem is blocking me on symfony tonight... I need to use the UserInterface class of the security component to retrieve information about the current user. However symfony tells me that this class doesn't exist. I checked "security" is well installed and the paths are good...
My code :
<?php
namespace App\Controller;
use App\Entity\Profile;
use App\Entity\Candidature;
use App\Form\CandidatureType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class CandidateController extends AbstractController
{
/**
* @Route("/candidate", name="candidate")
*/
public function new(Request $request, UserInterface $user): Response
{
// NEED TO BE CONNECTED !!
if ($user->getUsername()) {
// SOME CODE ...........
} else {
return $this->redirectToRoute('security_login');
}
}
}
Error i get (quote)
Cannot autowire argument $user of "App\Controller\CandidateController::new()": it references interface "Symfony\Component\Security\Core\User\UserInterface" but no such service exists. Did you create a class that implements this interface?