【问题标题】:using find() in cakephp3在 cakephp3 中使用 find()
【发布时间】:2015-11-17 07:21:23
【问题描述】:

如何使用 find() 来执行查询,例如:

select * from table1 
where status =1 and (title like '%keyword%' OR content like '%keyword%');

在 cakephp 3 中

【问题讨论】:

标签: sql cakephp datasource cakephp-3.0


【解决方案1】:

通过将函数用作orWhere()andWhere()的参数,您可以将条件与表达式对象组合在一起:

$query = $table1->find()
        ->where(['status' => 1])
        ->andWhere(function ($exp) {
            return $exp->or_([
                'title LIKE' => '%keyword%',
                'content LIKE' => '%keyword%'
            ]);
 });

或者你可以简单地使用下面的代码

$query = $table1->find()
    ->where([
        'status' => 1,
        'OR' => [['title LIKE' => '%keyword%'], ['content LIKE' => '%keyword%']],
    ]);

详情请见link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-17
    • 1970-01-01
    • 1970-01-01
    • 2018-12-16
    相关资源
    最近更新 更多