1 回答
TA贡献1934条经验 获得超2个赞
据我了解,您试图查找between指定时间段(如果已设置)的所有模型。
尝试这个:
public function search($params, $promotion_period)
{
$query = StaffEmploymentListView::find()->alias('LIST')
->joinWith(['employment']) //Here should be your relation name from StaffEmploymentListView model
->where(['LIST.EMPLOYMENT_TYPE' => 'PROMOTION']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 20,
],
'sort' => false
]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
$query->andFilterWhere(['like', 'DEPT_NAME', $this->DEPT_NAME])
->andFilterWhere(['like', 'COL_NAME', $this->COL_NAME])
->andFilterWhere(['like', 'GRADE_DESCR', $this->GRADE_DESCR])
->andFilterWhere(['like', 'DESG_NAME', $this->DESG_NAME])
->andFilterWhere(['like', 'TRIBE_NAME', $this->TRIBE_NAME])
->andFilterWhere(['like', 'GENDER', $this->GENDER])
->andFilterWhere(['like', 'HOME_DISTRICT', $this->HOME_DISTRICT]);
//$allModels = [];
if(is_array($promotion_period) && isset($promotion_period['to_date']) && isset($promotion_period['from_date'])){
//also check if you $promotion_period params are not empty
$to_date = strtotime($promotion_period['to_date']);
$from_date = strtotime($promotion_period['from_date']);
$query->andFilterWhere(['BETWEEN', 'EMPLOYMENT_TABLE_NAME.APPOINT_DATE', $from_date, $to_date]);
}
//Now you can get all your filtered models as array like this:
return $dataProvider->getModels();
}
- 1 回答
- 0 关注
- 104 浏览
添加回答
举报