Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii2-忽略';或';空时的条件_Php_Yii2 - Fatal编程技术网

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();