/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = DcmdNodeGroup::find()->orderBy("ngroup_name"); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 20]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['ngroup_id' => $this->ngroup_id, 'gid' => $this->gid]); $query->andFilterWhere(['like', 'ngroup_name', $this->ngroup_name]); return $dataProvider; }
public function actionConvert() { if (!array_key_exists('selection', Yii::$app->request->post())) { Yii::$app->getSession()->setFlash('error', '未选择设备!'); return $this->redirect(['index']); } $select = Yii::$app->request->post()['selection']; if (count($select) < 1) { Yii::$app->getSession()->setFlash('error', '未选择设备!'); return $this->redirect(['index']); } ///设备池 $query = DcmdNodeGroup::find()->asArray()->all(); $node_group = array(); foreach ($query as $item) { $node_group[$item['ngroup_id']] = $item['ngroup_name']; } ///获取需要变更的ip $ips_info = array(); $ids = ""; foreach ($select as $k => $id) { $model = $this->findModel($id); array_push($ips_info, array('id' => $id, 'ip' => $model->ip)); $ids .= $id . ";"; } return $this->render('select_group', ['ips_info' => $ips_info, 'ids' => $ids, 'node_group' => $node_group]); }