如何在Symfony中覆盖构造函数

时间:2018-11-30 12:55:19

标签: symfony fosuserbundle symfony-3.4

我想覆盖一个名为ConfirmAction的FOS用户操作。 在我的动作下面↓

/**
 * 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);}

如果我不覆盖构造函数,则会收到错误消息,指出未声明变量,例如$ 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

如果我将构造函数重写为:public function __construct(){}

我得到了错误:在null上调用成员函数findUserByConfirmationToken()

我应该重写构造函数吗?我该怎么办?

0 个答案:

没有答案