-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Too few arguments / Override RegistrationController #2695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Same with profile with symfony 3.3
I guess it has something to do with autowiring |
Same here ! with Symfony 3.3
|
For the moment i solved the problem with the overriding of the constructor:
This works for me, but i think it's not the most correct solution. |
Controller overriding is not something that is related to fos user bundle. There is not even documentation section about it in a 2.0 version. You can use events. Or if you want to override controllers you should go to the symfony documentation where you can find all information (note that controller is defined as a service). Possible bugs should be consult on symfony side too. Or third solution is to create your own controller. It is also not recommended to use |
it was in the 2.0 doc until 5 days ago... |
Ah ok my bad. They probably decided to remove, because it has nothing to do with this bundle. And maintenance was quite hard. Especially after publishing recent symfony versions. |
The problem is not directly with overriding of controllers (which is not best practice but sometimes you don't really have a choice and there is no reason it shouldn't work). I believe it has to do with autowiring configuration, but I didn't have time to look properly into it. |
The problem is with overriding. As I already said here is the section how to override any service. As you mentioned it tries to auto-wire your controller, but doesn't know how. That's why you have to create a compiler pass. |
To complete my answer. You should modify class Kernel extends BaseKernel implements CompilerPassInterface
{
#....
public function process(ContainerBuilder $container)
{
$definition = $container->findDefinition('fos_user.registration.controller');
$definition->setClass(App\Entity\Overrides\RegistrationController::class);
}
} And change the default service definition by excluding RegistrationController. # default service configuration
services:
App\:
resource: '../src/*'
exclude: '../src/{Entity,Migrations,Tests,Controller/Overrides}'
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
exclude: '../src/Controller/Overrides' Auto-wiring doesn't seem to recognize that this service was overridden. (so you are probably right that it comes from there) I am not sure if this is an expected behavior, but for sure it has nothing to do with fos user bundle. |
Same problem with s3.3 |
hi all, specialy @andevit @doctoome @r-ichard @grimmlink ,
|
I solved this by andevit solution, and adding a route before fos ones |
I found same issue and I didn't extend the controller. @sarpdorukaslan's fix helped me (I used ~2.0@dev) |
I'm just experiencing the same exact issue after a The complete error is this:
The new commit that causes the error is commit 32c2eed (release 2.1.1). Previously working release was (2.0.2, commit 2fc8a02). The complete error refers to JMSDIExtraBundle: this bundle caused issues with autowiring some time ago (see symfony/symfony#23200 and symfony/symfony#25695). I'm going to check the changes between the two commits and test the manual calling of |
Ok, I'm going closer to solve the problem (@andevit's solution is not a solution as it simply doesn't pass dependencies that may be required). In my MyNamespace\Bundle\UserBundle\Controller\:
resource: '../../src/MyNamespace/Bundle/UserBundle/Controller'
autowire: true The error that now comes out is:
As clearly stated by the error, this is caused by the fact that all controllers implement the interface The real problem is that they are aliased and this causes the error because the autowire cannot recognize which dependency set in which controller. To solve the problem in MyNamespace\Bundle\UserBundle\Controller\ProfileController:
tags: ['controller.service_arguments']
calls:
- [setContainer, ["@service_container"]]
bind:
$formFactory: "@fos_user.profile.form.factory" So, the complete configuration to solve the problem is this: MyNamespace\Bundle\UserBundle\Controller\:
resource: '../../src/MyNamespace/Bundle/UserBundle/Controller'
autowire: true
MyNamespace\Bundle\UserBundle\Controller\ProfileController:
tags: ['controller.service_arguments']
calls:
- [setContainer, ["@service_container"]]
bind:
$formFactory: "@fos_user.profile.form.factory" POSSIBLE SOLUTION ON FOSUserBundle side To ease the overriding it is possible to create 4 different concrete classes and typecast the controllers to them: this way each controller will have its own class and the autowiring is possible without manual configuration on our side. I've not explored this solution, so I don't know which changes it may require in the configuraation of services or in other parts of the bundle, but it is the definitive solution to not force developers to manually bind each overridden controller. |
Have a look at #2744 (comment) |
Symfony 4.3 ==> For me ProfileController overrider I add the empty construct and it works
|
what is the ControllerTrait ? what package? |
For a
This "break" was introduced in 2.1.0 |
SF 3.4
You also need this as standard:
|
Symfony 3.4: My
I changed those lines to:
And the error: |
You should not use this bundle anymore as it is discontinued.
|
Hi guys!
I'm a new symfony user.
Today I updated symfony to version 3.4.
I had already installed friendsofsymfony/user-bundle "~2.0@dev".
When I go on the registration page ( http://xxxxxx/app_dev.php/register/ ) I get this message:
Type error: Too few arguments to function FOS\UserBundle\Controller\RegistrationController::__construct(), 0 passed in /var/www/beta.jostratennis.com/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php on line 195 and exactly 4 expected
friendsofsymfony/user-bundle dev-master 5884948
Where can I find the solution?
The text was updated successfully, but these errors were encountered: