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 關注
- 128 瀏覽
添加回答
舉報