Skip to content

Too few argument exception on render(controller()) with Twig #2739

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

Closed
soullivaneuh opened this issue Feb 20, 2018 · 4 comments
Closed

Too few argument exception on render(controller()) with Twig #2739

soullivaneuh opened this issue Feb 20, 2018 · 4 comments

Comments

@soullivaneuh
Copy link

Symfony FOSUserBundle versions:

friendsofsymfony/user-bundle             v2.1.1            
symfony/monolog-bundle                   v3.1.2            
symfony/phpunit-bridge                   v3.4.4            
symfony/polyfill-apcu                    v1.7.0            
symfony/polyfill-intl-icu                v1.7.0            
symfony/polyfill-mbstring                v1.7.0            
symfony/polyfill-php56                   v1.7.0            
symfony/polyfill-php70                   v1.7.0            
symfony/polyfill-util                    v1.7.0            
symfony/security-acl                     v3.0.1            
symfony/swiftmailer-bundle               v3.2.0            
symfony/symfony                          v3.4.4            

Description of the problem including expected versus actual behavior:

When calling a FOSUser controller action from Twig, you have this kind of error:

ArgumentCountError: Too few arguments to function FOS\UserBundle\Controller\ProfileController::__construct(), 0 passed in /code/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php on line 195 and exactly 3 expected

Steps to reproduce:

Try this on a twig view:

{{ render(controller('FOSUserBundle:Profile:edit')) }}

It was because of #2639 introduced by @weaverryan

How can I call the controller like this if it require a service? I have to do it like that for ajax calls (the profile edit template is overridden).

Plus, AFAIK it's a BC break and should be introduced on next major. Am I wrong?

@soullivaneuh
Copy link
Author

Ok the solution is quite simple, use the service id instead:

{{ render(controller('fos_user.profile.controller:editAction')) }}

Still, it's a BC break to me. Dropping version support is good but it should not change the API.

If you think this one is acceptable, feel free to close this issue.

Regards.

@stof
Copy link
Member

stof commented Feb 20, 2018

hmm, do our controllers ever worked when being rendered inline ? I was not even aware that this would work fine (I don't even think it works by default, but requires some overrides).

Anyway, the FOSUserBundle:Profile:edit notation is incompatible with the usage of dependency injection, which is a must-have for proper Symfony 4 support (and this notation is even deprecated in Symfony 4.1).
So I don't want to revert this change to make a edge-case usage of the bundle work again (we never document anywhere that our controllers are embeddable, and as I said, I'm not even sure they are in the bundle itself)

@stof
Copy link
Member

stof commented Feb 20, 2018

I would accept a note in the upgrade file though if you submit a PR for it.

@soullivaneuh
Copy link
Author

It works, only the template are overridden.

So I don't want to revert this change to make a edge-case usage of the bundle work again (we never document anywhere that our controllers are embeddable, and as I said, I'm not even sure they are in the bundle itself)

I understand. Still, it's a possible way to do.

I would accept a note in the upgrade file though if you submit a PR for them.

Not really the time to do it right now and I think #2739 (comment) is an enough information. 😉

@XWB XWB closed this as completed May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants