scheb / two-factor-bundle

[ABANDONED] Two-factor authentication for Symfony 2 & 3 applications 🔐. Please use the newer versions from https://github.com/scheb/2fa.
https://github.com/scheb/2fa
MIT License
385 stars 111 forks source link

Type error: Too few arguments to function Scheb\TwoFactorBundle\Controller\FormController::__construct(), 0 passed #286

Closed herrieb closed 4 years ago

herrieb commented 4 years ago

Bundle version: v4.15.0 Symfony version: 3.4 PHP version: 7.1.22

Description I am following the installation guide as provided by the installation.md where i am trying to set the controller location in the config/routes.yaml

# config/routes.yaml
2fa_login:
    path: /2fa
    defaults:
        _controller: "scheb_two_factor.form_controller:form"

this doesnt work as form_controller does not exist at this location.

but:

2fa_login:
  path: /2fa
  defaults:
    _controller: "SchebTwoFactorBundle:form:form"

does exist. but it does not work as it needs 5 variables in the _construct which i do not have. I'm kind of stuck here. If it helps, the symfony version has been updated from 2.7 to 3.4

The specific error message i am getting right now is; HTTP 500 Internal Server Error Type error: Too few arguments to function Scheb\TwoFactorBundle\Controller\FormController::__construct(), 0 passed in C:\Users\user\Projects\test\app\cache\dev\jms_diextra\controller_injectors\SchebTwoFactorBundleControllerFormController.php on line 13 and exactly 5 expected

scheb commented 4 years ago

scheb_two_factor.form_controller:form should work, the scheb_two_factor.form_controller part is the name of the service definition, which is provided by the bundle, see here: https://github.com/scheb/two-factor-bundle/blob/master/Resources/config/two_factor.xml#L54-L60

Your workaround, using SchebTwoFactorBundle:form:form instead, cannot work. The application is missing information what services to inject into the constructor, therefore it doesn't pass any services and fails with the Too few arguments error message.

Using service names in routes is definitely a Symfony 3.4 feature, as it's described in the documentation.

In addition to using the logical name or the fully-qualified class name, Symfony supports a third way of referring to a controller. This method uses just one colon separator (e.g. service_name:indexAction) and refers to the controller as a service (see How to Define Controllers as Services).

So when you're saying "this doesnt work", what exactly doesn't work? Did you even try it?

herrieb commented 4 years ago

i really did try this before, but it did not work at the time.

I now copied and pasted it from your message, and voila it works.

keep up the great work!

vielen dank!