public function checkRule($attribute, $params) { if (!class_exists($this->name)) { $this->addError('name', Yii::t('users', 'CLASS_DO_NOT_EXISTS', ['phpClass' => $this->name])); } else { $newRule = new $this->name(); $existsRule = AuthRule::findOne(['name' => $newRule->name]); if ($existsRule) { $this->addError('name', Yii::t('users', 'RBAC_RULE_ALREADY_EXISTS', ['ruleName' => $newRule->name])); } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = AuthRule::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(['like', 'name', $this->name])->andFilterWhere(['like', 'data', $this->data]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getRuleName() { return $this->hasOne(AuthRule::className(), ['name' => 'rule_name']); }