/** * Lists all UserRole models. * @return mixed */ public function actionIndex() { $query = UserRole::find(); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => Yii::$app->params['pagination']]); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('index', ['models' => $models, 'pages' => $pages]); }
/** * 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; }
/** * 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]); } }