/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { /** @var ActiveQuery $query */ $query = Role::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Updates an existing User model. * If update is successful, the browser will be redirected to the 'view' page. * * @param int $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $model->scenario = User::SCENARIO_UPDATE; $roles = ArrayHelper::map(Role::find()->orderByName()->asArray()->all(), 'id', 'name'); if (Yii::$app->request->isPost) { // Traitement du formulaire if (!($model->load(Yii::$app->request->post()) && $model->save(true, null, true))) { Yii::$app->session->setFlash('flash-warning', HLib::t('messages', 'There are errors in your form')); } else { Yii::$app->session->setFlash('flash-success', HLib::t('messages', 'Update successful')); if (Yii::$app->request->getBodyParam('action') == 'saveAndBackToList') { return $this->redirect(Url::to(['/users/users/index', 'page' => 1])); } // On recharge les données pour être en phase avec la base sur les tables liées $model->refresh(); } } // Affichage ou ré-affichage return $this->render('update', compact('model', 'roles')); }