0

trying to use data transformer, I have an error when loadding my html form

In my formType class

use Doctrine\ORM\EntityManagerInterface;

class PmpType extends AbstractType
{
    private $entityManager;

    public function __construct(EntityManagerInterface $entityManager)
    {
        $this->entityManager = $entityManager;
    }
}

in my app\config\services.yml

services:
# default configuration for services in *this* file
 _defaults:
    # automatically injects dependencies in your services
    autowire: true
    # automatically registers your services as commands, event subscribers, etc.
    autoconfigure: true
    # this means you cannot fetch services directly from the container via $container->get()
    # if you need to do this, you can override this setting on individual services
    public: true

but I received this error

Type error: Too few arguments to function myApp\Bundle\Form\PmpType::__construct(), 0 passed in \vendor\symfony\symfony\src\Symfony\Component\Form\FormRegistry.php on line 92 and exactly 1 expected

What do I miss

Thx for hepl

2 Answers 2

1

OK I don't understand why but I have toset the service for my class : in service.yml, I add

    seims_pmp.pmptype:
      class: SEISM\PmpIG56Bundle\Form\PmpType
      arguments: ["@doctrine.orm.entity_manager"]
      tags: [form.type]

and now it's working

Sign up to request clarification or add additional context in comments.

Comments

0

I had a similar problem.

My form file
namespace App\Form;

use App\Form\DataTransformer\PlaceToNumberTransformer;
use App\Entity\PlaceYoutube;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PlaceYoutubeType extends AbstractType
{

had a name: PlaceYoutube.php

I renamed it to: PlaceYoutubeType.php

and the problem was solved :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.