Doctrine2表达式eq用于匹配所有的特殊字符

Han*_*ncs 5 php sql symfony doctrine-orm

我正在尝试使用doctrine查询构建器运行过滤器,我正在使用expr eq,但是如果我没有过滤器值,我想使用一些特殊符号来表示所有行的expr eq.

我的代码:

$q = $qb->select(array('p'))
                ->from(payment::class, 'p')
                ->innerJoin(customer::class, 'z', 'WITH', 'p.customer= z.id')
                ->where(                            
                        $qb->expr()->eq('z.id', '?2')
                )
                ->setMaxResults($limit)
                ->setFirstResult($offset)
                ->orderBy('p.'.$sortField, $sortType) 
Run Code Online (Sandbox Code Playgroud)

在那里我想要像( - > setParameter(2,"*"))

                ->setParameter(2, $filtry['customer'])
                ->getQuery();

        return $q->getResult();
Run Code Online (Sandbox Code Playgroud)

可能吗?我不想为每个过滤器编写不同的查询构建器.

对不起我的英语不好

谢谢

Mat*_*teo 3

它是一个查询生成器,因此您可以有条件地添加参数,例如:

$qb->select(array('p'))
                ->from(payment::class, 'p')
                ->innerJoin(customer::class, 'z', 'WITH', 'p.customer= z.id')
                ->setMaxResults($limit)
                ->setFirstResult($offset)
                ->orderBy('p.'.$sortField, $sortType) 


if ($filtry['customer'])
{
$qb->andWhere(                            
              $qb->expr()->eq('z.id', $filtry['customer'])
                )
};

$q = $qb->getQuery()
Run Code Online (Sandbox Code Playgroud)

希望这有帮助