0

I want to override an FOS User action named confirmAction. Here below my action ↓

/**
 * Receive the confirmation token from user email provider, login the user.
 *
 * @param Request $request
 * @param string  $token
 *
 * @return Response
 */
public function confirmAction(Request $request, $token)
{
    $utilisateur = $this->getDoctrine()
        ->getRepository(Utilisateur::class)
        ->findOneByConfirmationToken($token);

    $utilisateur->setMyAttribute(null);
    $em = $this->getDoctrine()->getManager();
    $em->persist($utilisateur);
    $em->flush();

    return parent::confirmAction($request, $token);}

If I dont overwrite the constructor I got the error that say the variables are not declared like $userManager, $eventDispatcher...

Type error: Argument 1 passed to FOS\UserBundle\Controller\RegistrationController::__construct() must implement interface Symfony\Component\EventDispatcher\EventDispatcherInterface, none given, called in /var/www/html/linguanomad/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php on line 195

If I override the constructor as : public function __construct(){}

I got the error : Call to a member function findUserByConfirmationToken() on null

Should I override the constructor ? How should I do that ?

  • How are you instantiating your class? If you are using the new operator then that would be wrong. If you are using the service container then show your service definition if any. – Cerad Nov 30 '18 at 13:23
  • Basically `__construct` in doctrine entity is called directly in end user code. Doctrine does not use construct when fetch entities from database. – Paul Nov 30 '18 at 13:59

0 Answers0