Open wuxian-wifi opened 6 years ago
App\Controller\RegistrationController: arguments: $formFactory: '@fos_user.registration.form.factory'
Change services.yaml
Well, why are you trying to define your own form facotry services if you override the controller ?
In Symfony 4 I have such error, when i try to overwrite the register controller:
Cannot autowire service "App\Controller\RegisterController": argument "$formFactory" of method "__construct()" references interface "FOS\UserBundle\Form\Factory\FactoryInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "fos_user.profile.form.factory", "fos_user.registration.form.factory", "fos_user.change_password.form.factory", "fos_user.resetting.form.factory".
Hi @si4kar, i defined the controller in services.yaml but my function not working.. (I use symfony 4.2)
App\Controller\RegistrationController:
arguments:
$formFactory: '@fos_user.registration.form.factory'
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\UserBundle\Controller\RegistrationController as BaseController;
use FOS\UserBundle\Event\GetResponseUserEvent;
use Symfony\Component\HttpFoundation\Request;
class RegistrationController extends BaseController
{
public function registerAction(Request $request)
{
dd('oko');
}
}
Have you an idea ?
Thanks
Symfony 4.2 uses DI. You should be able to define all the interfaces/factories in your controller _construct().. add them to the use clauses. Should just work if you have autowiring set to true.
I just had to do this with our legacy app. You have to do some work in 3.4... YMMV
services.yml
MyUserBundle\Controller\RegistrationController:
tags: ['controller.service_arguments']
arguments:
$eventDispatcher: '@event_dispatcher'
$formFactory: '@fos_user.registration.form.factory'
$userManager: '@fos_user.user_manager'
$tokenStorage: '@security.token_storage'
In your controller.
use FOS\UserBundle\Form\Factory\FactoryInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager, TokenStorageInterface $tokenStorage)
{
$this->eventDispatcher = $eventDispatcher;
$this->formFactory = $formFactory;
$this->userManager = $userManager;
$this->tokenStorage = $tokenStorage;
}
Hi, I've the same problem than @si4kar in symfony 4.4. How I can override registrationController?
Hi @joseadame and @si4kar , you could configure this working definition:
# app/config/services.yaml
fos_user.registration.controller:
class: App\Application\UserBundle\Controller\RegistrationController
FOS\UserBundle\Form\Factory\FactoryInterface: '@fos_user.registration.form.factory'
(Source: Using Aliases to Enable Autowiring)
Hello,
I tried to override the registration controller for adding some custom fields, like register date. But I have some problems:
app/config/services.yaml:
app/config/routes.yaml:
app/Controller/RegistrationController:
Thank you in advance :)