正则表达式,带有“错误:无效的PathExpression。必须为StateFieldPathExpression。”

时间:2019-08-05 13:22:23

标签: regex symfony doctrine-orm doctrine doctrine-query

我有一个$value变量,其中包含“ Open | Close”。我想在Symfony中使用一个学说查询来获取所有带有“打开”或“关闭”字样的“状态”。为此,我尝试使用正则表达式。但是,出现以下错误:

  

[语义错误]第0行,'status,:regexp)附近的col 75:错误:
  无效的PathExpression。必须是StateFieldPathExpression。

这是我的代码:

$qb = $this->createQueryBuilder('q')
->andWhere('REGEXP(q.status, :regexp) = true')
->setParameter('regexp', '|');

我有DoctrineExtensionsBundle,并且我已经更新了app/config.yml

1 个答案:

答案 0 :(得分:1)

如何使用explode()函数和SQL IN运算符?

$qb = $this->createQueryBuilder('q')
  ->andWhere('q.status IN (:status)')
  ->setParameter(':status', explode('|', $value));

它将返回状态列中具有“打开”或“关闭”的所有记录。