【发布时间】:2012-12-23 13:13:21
【问题描述】:
/已编辑/
我有这门课:
namespace Baza\BlogBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\EntityManager;
class filterType extends AbstractType
{
protected $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->$em->getDoctrine()->getEntityManager();
/****
****/
}
}
这是我的服务 yml:
services:
filterType:
class: Baza\BlogBundle\Form\filterType
arguments: [doctrine.orm.entity_manager]
当我运行代码时,出现以下异常:
可捕获的致命错误:传递给 Baza\BlogBundle\Form\filterType::__construct() 的参数 1 必须是 Doctrine\ORM\EntityManager 的实例,没有给出
我完全没有想法。
【问题讨论】:
-
试试:
arguments: [@doctrine.orm.entity_manager]添加了@,不知道是什么意思,但我所有的 Symfony 代码都使用它。 -
我试过了,我得到:“扫描下一个令牌时出现 ScannerException,我们在编辑器中发现了这个无法启动任何令牌的字符 @(64)”。
-
确保您的空格数正确。
-
为什么要添加
Form类型为 DoctrineprePersist? -
我正在尝试一些东西,我很确定这不会导致这里出现错误。
标签: php symfony doctrine doctrine-orm