regex - 带有教义“错误:无效的 PathExpression。必须是 StateFieldPathExpression”的正则表达式。
问题描述
我有一个$value
包含“打开|关闭”的变量。我想在 Symfony 中使用学说查询来获取所有带有“打开”或“关闭”一词的“状态”。为此,我尝试使用正则表达式。但是,我收到以下错误:
[语义错误] line 0, col 75 near 'status, :regexp)': Error:
Invalid PathExpression。必须是 StateFieldPathExpression。
这是我的代码:
$qb = $this->createQueryBuilder('q')
->andWhere('REGEXP(q.status, :regexp) = true')
->setParameter('regexp', '|');
我有DoctrineExtensionsBundle
并且我已经更新了我的app/config.yml
解决方案
使用explode() 函数和SQL IN 运算符怎么样?
$qb = $this->createQueryBuilder('q')
->andWhere('q.status IN (:status)')
->setParameter(':status', explode('|', $value));
它将返回在状态列中具有“打开”或“关闭”的所有记录。
推荐阅读
- python - 我的服务器(Python 套接字)有什么问题?
- python - 从熊猫列中删除停用词
- jenkins-groovy - 在 Jenkins Groovy 共享库设计中使用 sh() 与 execute() - 在主机之间切换?
- javascript - 修改对象数组中的值
- amazon-web-services - 使用 AWS Api Gateway 设置自定义域
- java - 简单的 Java 程序在 NetBeans IDE 中运行,但在构建时不运行
- web - HTTPS ngrok 隧道能否成为运行生产服务器的安全方式?
- html - Django 尝试渲染甚至被注释掉的 HTML 代码,这会导致错误
- java - “if(map.get(key)-map1.getOrDefault(key, 0)!=0)”和“if(map.get(key)!=map1.getOrDefault(key, 0))”有什么区别
- javascript - 在静态 HTML 中使用 Material-UI React