пятница, 28 января 2022 г.

[Symfony] "FormType too few arguments passed 0, 1 argument needed" fix

It can be not only FormType, also can be any your custom form type. 

It can be when you moved your form into new namespace/bundle, but did not registered services in it. 

  1. don't forget that your form should extend Symfony\Component\Form\AbstractType;
  2. add new bundle namespace in composer.json
  3. Create bundle extension file in ./DependencyInjection/FooExtenstion like this https://symfony.com/doc/current/bundles/extension.html
  4. add this into your bundle services.yaml:
services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true

    FooBundle\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'
            - '../src/Tests/'
        5. run php bin/console cache:clear

Комментариев нет:

Отправить комментарий