我在 Doctrine 2 ORM 中的一个非常简单的查询中遇到了问题。我确信我已经严格按照文档进行操作,但它就是行不通。我有这个:
$qb = $this->em->createQueryBuilder()
->select('p')
->from('Property', 'p')
->where('type = :type');
$properties = $qb->getQuery()->setParameters(array(
'type' => 'house',
))->getResult();
我得到:
QueryException: [Semantical Error] line 0, col 46 near 'type = :type': Error: 'type' is not defined.
我也尝试过:
$properties = $qb->getQuery()->setParameters(array(
':type' => 'house',
))->getResult();
没有运气。我确信这一定很简单,但我就是看不出哪里出了问题。
谢谢。
最佳答案
->where('p.type = :type');
您始终必须指定属性的所有者 - 在本例中为 Property
实体。
关于php - Doctrine 2 ORM问题设置参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5184312/