0
votes

I need to override the regitration contrller by 1 in my bundle.

I made the file inside userbundle, but it gives that error that I saw a lot at stackoverflow but no reply.

Error is

ContextErrorException: Runtime Notice: Declaration of TA\UserBundle\Controller\RegistrationController::registerAction() should be compatible with FOS\UserBundle\Controller\RegistrationController::registerAction(Symfony\Component\HttpFoundation\Request $request) in E:\php\xampp\htdocs\platform\src\TA\UserBundle\Controller\RegistrationController.php line 9

Controller

<?php

//src\TA\UserBundle\Controller\RegistrationController.php
namespace TA\UserBundle\Controller;

use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\UserBundle\Controller\RegistrationController as BaseController;

class RegistrationController extends BaseController
{ 
    public function registerAction()
    {
        $form = $this->container->get('fos_user.registration.form');
        $formHandler = $this->container->get('fos_user.registration.form.handler');
        $confirmationEnabled = $this->container->getParameter('fos_user.registration.confirmation.enabled');

        $process = $formHandler->process($confirmationEnabled);
        if ($process) {
            $user = $form->getData();

            /*****************************************************
             * Add new functionality (e.g. log the registration) *
             *****************************************************/
            $this->container->get('logger')->info(
                sprintf('New user registration: %s', $user)
            );

            if ($confirmationEnabled) {
                $this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
                $route = 'fos_user_registration_check_email';
            } else {
                $this->authenticateUser($user);
                $route = 'fos_user_registration_confirmed';
            }

            $this->setFlash('fos_user_success', 'registration.flash.user_created');
            $url = $this->container->get('router')->generate($route);

            return new RedirectResponse($url);
        }

        return $this->container->get('templating')->renderResponse('FOSUserBundle:Registration:register.html.'.$this->getEngine(), array(
            'form' => $form->createView(),
        ));
    }
}

even when I changed

 public function registerAction()  

to

public function registerAction(Request $request)

error became

ContextErrorException: Runtime Notice: Declaration of TA\UserBundle\Controller\RegistrationController::registerAction() should be compatible with FOS\UserBundle\Controller\RegistrationController::registerAction(Symfony\Component\HttpFoundation\Request $request) in E:\php\xampp\htdocs\platform\src\TA\UserBundle\Controller\RegistrationController.php line 9

2

2 Answers

1
votes

This one worked for me. My Example:

<?php
namespace FRMKS\FoodR\FoodApp\Controller;

use FOS\UserBundle\Controller\RegistrationController as BaseController;
use Symfony\Component\HttpFoundation\Request;

class RegistrationController extends BaseController
{
    public function registerAction(Request $request)
    {
        $response = parent::registerAction($request);

        // ... do custom stuff

        return $response;

    }
}

Basically you need to add use of request, parameter 'Request $request' to 'registerAction' function and pass 'request' param to parent 'registerAction' function

0
votes

Did you try to put the full 'Symfony\Component\HttpFoundation\Request $request' into your method definition?

public function registerAction(Symfony\Component\HttpFoundation\Request $request) {}