Last active
November 18, 2016 04:05
-
-
Save wakasann/ccf5b0ecd8c36fae6c9b005de1592e0b to your computer and use it in GitHub Desktop.
yii2 where or and like
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// where status='Open' and category='1' and subCategory='1' and (category like '%test%' or subCategory like '%test%' or title like '%test%' or introduction like '%test%') | |
//@link http://stackoverflow.com/a/31558035/5840474 get and or | |
//@link http://stackoverflow.com/a/28593956/5840474 get like | |
$where = array( | |
array( | |
'and', | |
"status='Open'" | |
) | |
); | |
if(!empty($category)){ | |
$where[0][] = "category='$category'"; | |
} | |
if(!empty($subCategory)){ | |
$where[0][] = "subCategory='$subCategory'"; | |
} | |
if(!empty($word)){ | |
$where[] = array( | |
'or', | |
array('like','category',$word), | |
array('like','subCategory',$word), | |
array('like','title',$word), | |
array('like','introduction',$word), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment