/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = JumperInfo::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ["pageSize" => 10]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'port', $this->port])->andFilterWhere(['like', 'wire_frame', $this->wire_frame])->andFilterWhere(['like', 'wire_position', $this->wire_position])->andFilterWhere(['like', 'point', $this->point])->andFilterWhere(['like', 'insert_no', $this->insert_no])->andFilterWhere(['like', 'tag', $this->tag]); $query->orderBy('id desc'); return $dataProvider; }
public function actionExport() { $data = JumperInfo::find()->select(['ip', 'port', 'wire_frame', 'wire_position', 'point', 'tag'])->asArray()->all(); $excel_arr = []; $excel_arr[] = ['交换机IP', '设备端口', '线架号', '线架位置', '线架端口', '点位标签']; $excel_arr = array_merge($excel_arr, $data); ob_start(); $this->saveExcel($excel_arr, '跳线管理'); $content = ob_get_contents(); ob_end_clean(); $file_name = 'jumper.xlsx'; Yii::$app->response->sendContentAsFile($content, $file_name); }