/**
  * Setup search function for filtering and sorting
  * based on fullName field
  * @param $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = SettingModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['status' => $this->status]);
     $query->andFilterWhere(['section' => $this->section]);
     $query->andFilterWhere(['type' => $this->type]);
     $query->andFilterWhere(['like', 'key', $this->key]);
     $query->andFilterWhere(['like', 'value', $this->value]);
     return $dataProvider;
 }
 /**
  * Finds a Setting model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return SettingModel the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = SettingModel::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#3
0
use yii2mod\settings\models\SettingModel;
/* @var $dataProvider \yii\data\ActiveDataProvider */
/* @var $searchModel \yii2mod\settings\models\search\SettingSearch */
$this->title = Yii::t('yii2mod.settings', 'Settings');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="setting-index">
    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p><?php 
echo Html::a(Yii::t('yii2mod.settings', 'Create Setting'), ['create'], ['class' => 'btn btn-success']);
?>
</p>
    <?php 
Pjax::begin(['timeout' => 10000, 'enablePushState' => false]);
?>
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'type', 'filter' => SettingType::listData(), 'filterInputOptions' => ['prompt' => Yii::t('yii2mod.settings', 'Select Type'), 'class' => 'form-control']], ['attribute' => 'section', 'filter' => ArrayHelper::map(SettingModel::find()->select('section')->distinct()->all(), 'section', 'section'), 'filterInputOptions' => ['prompt' => Yii::t('yii2mod.settings', 'Select Section'), 'class' => 'form-control']], 'key', 'value:ntext', ['class' => EditableColumn::class, 'attribute' => 'status', 'url' => ['edit-setting'], 'value' => function ($model) {
    return SettingStatus::getLabel($model->status);
}, 'type' => 'select', 'editableOptions' => function ($model) {
    return ['source' => SettingStatus::listData(), 'value' => $model->status];
}, 'filter' => SettingStatus::listData(), 'filterInputOptions' => ['prompt' => Yii::t('yii2mod.settings', 'Select Status'), 'class' => 'form-control']], ['header' => Yii::t('yii2mod.settings', 'Actions'), 'class' => 'yii\\grid\\ActionColumn', 'template' => '{update}{delete}']]]);
?>
    <?php 
Pjax::end();
?>
</div>