Issue
How can I use find() to execute queries such as :
select * from table1
where status =1 and (title like '%keyword%' OR content like '%keyword%');
in cakephp 3
Solution
By using functions as the parameters to orWhere()
and andWhere()
, you can compose conditions together with the expression objects:
$query = $table1->find()
->where(['status' => 1])
->andWhere(function ($exp) {
return $exp->or_([
'title LIKE' => '%keyword%',
'content LIKE' => '%keyword%'
]);
});
or you can simply use below code
$query = $table1->find()
->where([
'status' => 1,
'OR' => [['title LIKE' => '%keyword%'], ['content LIKE' => '%keyword%']],
]);
For details please see link
Answered By - Alimon Karim
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.