Php Yii2-忽略';或';空时的条件
我有一个很好的问题Php Yii2-忽略';或';空时的条件,php,yii2,Php,Yii2,我有一个很好的问题 $order_items= OrderItem::find() ->where(['location_id'=>$model->location_name,'instructor_id'=>$model->instructor_name]) ->andwhere(['between', 'date', $model->from_date, $model->to_date ])->all(); 但是当$model->讲师姓
$order_items= OrderItem::find()
->where(['location_id'=>$model->location_name,'instructor_id'=>$model->instructor_name])
->andwhere(['between', 'date', $model->from_date, $model->to_date ])->all();
但是当$model->讲师姓名
为空或null时,我得到的结果为null。
所以我想在讲师id
为空时忽略
什么时候
'讲师id'=>$model->讲师姓名或讲师id'=>Null
我怎么能做到
$order_items= OrderItem::find()
->where(['location_id'=>$model->location_name,'instructor_id'=>$model->instructor_name])
->andWhere(['not', ['instructor_id' => null]])
->andwhere(['between', 'date', $model->from_date, $model->to_date ])->all();
或添加以下内容
->andWhere(['<>', 'instructor_id', null])
或添加以下内容
->andWhere(['<>', 'instructor_id', null])
你应该使用
你应该使用
$order_items = OrderItem::find()
->where(['location_id' => $model->location_name])
->andFilterWhere(['instructor_id' => $model->instructor_name])
->andwhere(['between', 'date', $model->from_date, $model->to_date ])
->all();