select 元素在其中一个属性中有/没有一些 string/regex 的语法是什么?

What is the syntax to select elements which have / dont have some string/regex in one of their attributes?

我正在尝试这样做:

$em->createQueryBuilder('u')
->select('u')
->// where  u.username doesnt contain the string "desactive" 

另外,我读了 the querybuilder documentation,我想知道我是否应该使用 Expr class。 但是,这个 class 的目的对我来说非常模糊,几乎没有解释:

To workaround some of the issues that add() method may cause, Doctrine created a class that can be considered as a helper for building expressions. This class is called Expr, which provides a set of useful methods to help build expressions:

Morevoer,是我还是完全没有解释它的某些方法的作用? (我说的是伪函数对象和函数对象部分)

我是不是完全漏掉了什么:(?

我没有测试,但你可以使用 'notLike'

根据doctrine query builder documentation

编辑:'%desactive%' qb->expr()->literal('%desactive%')

$qb = $this->getEntityManager()->createQueryBuilder();

return $qb->add('select','u')
          ->from('YOURBUNDLE:YOURENTITY','u')
          ->where($qb->expr()->notLike('u.username', qb->expr()->literal('%desactive%'))
          ->getQuery()->getResult();