cakephp - 如何为单个列添加多个条件?

标签 cakephp cakephp-2.x

我有很多句子需要对同一列进行过滤:

'conditions' => array('Zona.nombre LIKE' => $buscar,
                      'Zona.nombre LIKE' => 'CUPONATIC%',
                      'Zona.nombre LIKE' => 'GROUPON%'
),

最佳答案

你的问题不是很清楚,但我想问题是你多次使用同一个数组键

你甚至没有提到 cakephp 版本,但它似乎是 cake2

如果我没记错的话,cake2 的解决方法是将每个条件放在不同的数组中

'conditions' => array(
     array('Zona.nombre LIKE' => $buscar),
     array('Zona.nombre LIKE' => 'CUPONATIC%'),
     array('Zona.nombre LIKE' => 'GROUPON%')
),

编辑:当然,这样您就可以在 AND 中加入 3 个条件。

将它们放在OR中似乎更符合逻辑

'conditions' => array(
    'OR' => array(
         array('Zona.nombre LIKE' => $buscar),
         array('Zona.nombre LIKE' => 'CUPONATIC%'),
         array('Zona.nombre LIKE' => 'GROUPON%')
    )
),

关于cakephp - 如何为单个列添加多个条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46202154/

相关文章:

php - CakePHP:根据配置值全局更改所有模型的数据库连接

cakephp - 如何在 CakePHP 2.3 中设置 SameSite Cookie 属性?

php - 读取 webroot 之上的文件

cakephp Controller 的 jquery getJSON() 响应为空,但 200 成功

caching - 如何在 CakePHP 中的模型函数内使用助手

mysql - CakePHP 排序顺序不影响所有记录

php - CakePHP 3 Query Builder - 如何在条件下使用 max 函数?

cakephp - 如何更改 CakePHP 3 中 Controller 的 View block 内容?

php - 在 Cakephp 中验证 Bootstrap 表单