/** * Lists all Role models. * @return mixed */ public function actionIndex() { if (!$this->is_access('role/index')) { Yii::$app->session->setFlash('error', $this->errorInfo); return $this->redirect($this->redirectUrl); } $dataProvider = new ActiveDataProvider(['query' => Role::find()]); Yii::$app->view->params['meta_title'] = '角色管理'; return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $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, 'is_membership_possible' => $this->is_membership_possible, 'price' => $this->price, 'duration' => $this->duration]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $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, 'role_value' => $this->role_value]); $query->andFilterWhere(['like', 'role_name', $this->role_name]); return $dataProvider; }
public static function isRoleNameValid($role_name) { $role = Role::find('role_name')->where(['role_name' => $role_name])->one(); return isset($role->role_name) ? true : false; }