Beispiel #1
0
 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;
 }
Beispiel #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRuleName()
 {
     return $this->hasOne(AuthRule::className(), ['name' => 'rule_name']);
 }
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'description')->textarea(['rows' => 6]);
?>

    <?php 
echo $form->field($model, 'data')->textarea(['rows' => 6]);
?>

    <?php 
echo $form->field($model, 'rule_name')->dropDownList(ArrayHelper::map(AuthRule::find()->all(), 'name', 'name'), ['prompt' => Yii::t('users', 'SELECT...')]);
?>

    <?php 
echo Html::hiddenInput('AuthItem[type]', $type);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('users', 'CREATE') : Yii::t('users', 'UPDATE'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>