0

I don't know why this won't work:

->add('productSearchType', EntityType::class, array(
                'label' => 'entity.text.product.product_search_number_type',
                'class' => AC\ProductBundle\Entity\ProductSearchType::class,
                'choice_label' => 'designation',
                'expanded' => false,
                'placeholder' => 
'entity.text.product.select_product_search_number_type',
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('e')
                            ->orderBy('e.designation', 'ASC');
                },
            ))

That's the error message:

Catchable Fatal Error: Argument 1 passed to
Symfony\Bridge\Doctrine\Form\Type\DoctrineType::__construct()
must implement interface Doctrine\Common\Persistence\ManagerRegistry,
none given, called in (...)\src\Symfony\Component\Form\FormRegistry.php
on line 85 and defined (...)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Adam
  • 1
  • 1
  • Show us how the form is instantiated. You probably did something like `new YourFormType();` instead of getting the form through a form factory service or alike (which is container aware). – Mike Doe Apr 12 '17 at 09:53
  • $entity = $this->productService->getVariant($id); $form = $this->formFactory->create(VariantType::class, $entity, array( 'method' => 'POST', )); – Adam Apr 25 '17 at 10:33
  • How did you inject the formFactory property then? – Mike Doe Apr 25 '17 at 12:21

1 Answers1

0

Try creating your form like this, so the form factory gets access to the container:

$form = $this->get('form.factory')
    ->create(VariantType::class, $entity, ['method' => 'POST'])
    ->getForm();
Mike Doe
  • 16,349
  • 11
  • 65
  • 88