Doctrine 2 DQL:无法重用命名参数?

时间:2010-12-18 12:03:38

标签: php doctrine-orm dql

我发现我无法执行以下操作,请注意“:user”使用了两次

$query = $em->createQuery('select p from Application\Models\Project p
                           WHERE  p.owner = :user
                           OR :user MEMBER OF p.collaborators');
$query->setParameter('user', $user);

我收到错误“array_combine(): Both parameters should have an equal number of elements

我可以通过执行类似下面的操作来解决问题

$query = $em->createQuery('select p from Application\Models\Project p
                           WHERE  p.owner = :user
                           OR :user1 MEMBER OF p.collaborators');

1 个答案:

答案 0 :(得分:3)

如果您使用?X,您可以这样做。

$query = $em->createQuery('select p from Application\Models\Project p
                           WHERE  p.owner = ?0
                           OR ?0 MEMBER OF p.collaborators');
$query->setParameters(array($user));