我试着在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;
}
答案 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;
}