Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UserRole::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, 'state' => $this->state, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'role_name', $this->role_name])->andFilterWhere(['like', 'role_description', $this->role_description])->andFilterWhere(['like', 'role_key', $this->role_key]);
     return $dataProvider;
 }
Пример #2
0
 /**
  * Updates an existing UserAuthorize model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $account = UserAccount::findOne($id);
     $user = UserAccount::find()->select('id, username')->all();
     $role = UserRole::find()->select('id,role_name')->all();
     if ($model->load(Yii::$app->request->post())) {
         $model->updated_at = date("Y-m-d H:i:s");
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             // print_r($model->errors);
             return $this->render('update', ['model' => $model, 'user' => $user, 'role' => $role, 'account' => $account]);
         }
     } else {
         // print_r($model->errors);
         return $this->render('update', ['model' => $model, 'user' => $user, 'role' => $role, 'account' => $account]);
     }
 }
Пример #3
0
 public function getRole()
 {
     return $this->hasOne(UserRole::className(), ['id' => 'role_id']);
 }
Пример #4
0
 /**
  * Finds the UserRole model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return UserRole the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = UserRole::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }