/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = DcmdDepartment::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 20]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['depart_id' => $this->depart_id, 'utime' => $this->utime, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]); $query->andFilterWhere(['like', 'depart_name', $this->depart_name])->andFilterWhere(['like', 'comment', $this->comment]); return $dataProvider; }
protected function getDepart() { $ret = DcmdDepartment::find()->asArray()->all(); $depart = array(); foreach ($ret as $item) { $depart[$item['depart_id']] = $item['depart_name']; } return $depart; }
/** * Updates an existing DcmdUser model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { if (Yii::$app->user->getIdentity()->admin != 1 || Yii::$app->user->getIdentity()->sa != 1) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!"); return $this->redirect(array('index')); } $model = $this->findModel($id); $ret = DcmdDepartment::find()->asArray()->all(); $depart = array(); foreach ($ret as $item) { $depart[$item['depart_id']] = $item['depart_name']; } if (Yii::$app->request->post()) { $model->utime = date('Y-m-d H:i:s'); $model->opr_uid = Yii::$app->user->getId(); if ($model->load(Yii::$app->request->post())) { if ($model->admin != 1) { $model->sa = 0; } if ($model->save()) { $this->oprlog(2, "update user:"******"修改成功"); return $this->redirect(['view', 'id' => $model->uid]); } } $err_str = ""; foreach ($model->getErrors() as $k => $v) { $err_str .= $k . ":" . $v[0] . "<br>"; } Yii::$app->getSession()->setFlash('error', "修改失败失败:" . $err_str); } return $this->render('update', ['model' => $model, 'depart' => $depart]); }