0
votes

I am tryin to inject the entity manager in a formbuilder class. But i get this error :

Catchable Fatal Error: Argument 1 passed to Pdb\Backend\Admin\RelationManagementBundle\Form\Search\SearchForm::__construct() must be an instance of Doctrine\ORM\EntityManager, none given.

services:
    my_service:
        class:      Pdb\Backend\Admin\RelationManagementBundle\Form\Search\SearchForm
        arguments:  
            entityManager: "@doctrine.orm.entity_manager"

my constructor :

class SearchForm extends AbstractType {

protected $entityManager;

public function __construct(EntityManager $entityManager) {
    $this->entityManager = $entityManager;
}
1
I'm guessing you are doing: $searchForm = new SearchForm(); If so then that won't work. Need to use the service container and you will probably need to tag it as a form service. symfony.com/doc/current/cookbook/form/… - Cerad
do you get this error at a specific point in your application or in general? - jahller
Thanks for the answers. I think i need to tag it as a form service but i don't fully understand how to do this. Maybe somebody got some examples ? - Tommie

1 Answers

0
votes

in controller

public function showAction($id,$tab)
    {
...
        $em = $this->getDoctrine()->getManager();

        $form    = $this->createForm(new Pdb\Backend\Admin\RelationManagementBundle\Form\Search\SearchForm($em), $entity);


..
}

then in form

class SearchForm extends AbstractType {

protected $entityManager;

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