在formbuilder类中注入doctrine

时间:2014-03-24 11:14:34

标签: php symfony doctrine

我试着在formbuilder类中注入实体管理器。 但是我得到了这个错误:

捕获致命错误:传递给Pdb \ Backend \ Admin \ RelationManagementBundle \ Form \ Search \ SearchForm :: __ construct()的参数1必须是Doctrine \ ORM \ EntityManager的实例,没有给出。

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

我的构造函数:

class SearchForm extends AbstractType {

protected $entityManager;

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

1 个答案:

答案 0 :(得分:0)

控制器中的

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

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


..
}

然后以表格

class SearchForm extends AbstractType {

protected $entityManager;

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