Speaktech.in

Dynamic query where clause in yii

To add where clause dynamically we can use the below method:

$res = propertyDetail::find()->joinWith('propertyImages');$res = $res->where(['pkPropertyIDPrimary'=>1])->all();

//Another example : 
$products = Products::find();
  if(!empty($search->name)){
           $products= $products 
               ->andwhere(['LIKE', 'ProductName', $search->name,]);} 
 $products= $products->all();