コード例 #1
0
 /**
  * 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]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'data', $this->data]);
     return $dataProvider;
 }
コード例 #2
0
ファイル: _form.php プロジェクト: burnb/yii2-rbac-cms-module
use yii\bootstrap\ActiveForm;
use yii\jui\AutoComplete;
use yii\helpers\Html;
use yii\rbac\Item;
use bariew\rbacModule\models\AuthRule;
use bariew\rbacModule\models\AuthItem;
/**
 * @var yii\web\View $this
 * @var AuthItem $model
 * @var yii\widgets\ActiveForm $form
 */
$form = ActiveForm::begin();
if ($model->type == Item::TYPE_ROLE) {
    echo $form->field($model, 'name')->textInput();
} else {
    if ($model->isNewRecord) {
        echo Html::activeLabel($model, 'name') . '<br />' . AutoComplete::widget(['model' => $model, 'attribute' => 'name', 'clientOptions' => ['source' => array_values($model::permissionList()), 'delay' => 0, 'autoFocus' => true, 'minLength' => 0]]);
    }
}
if ($model->type == Item::TYPE_PERMISSION) {
    echo $form->field($model, 'rule_name')->dropDownList(AuthRule::listAll(), ['prompt' => false]);
}
echo $form->field($model, 'description')->textarea(['rows' => 6]);
?>
<div class="form-group">
    <?php 
echo \yii\helpers\Html::submitButton($model->isNewRecord ? Yii::t('modules/rbac', 'Create') : Yii::t('modules/rbac', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
</div>
<?php 
ActiveForm::end();
コード例 #3
0
 public function down()
 {
     return AuthRule::deleteAll(['name' => 'author_rule']);
 }
コード例 #4
0
 /**
  * Finds the AuthRule model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return AuthRule the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AuthRule::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }