/**
  * Finds the DictCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return DictCategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DictCategory::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = DictCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
示例#3
0
<?php

use yii\helpers\Html;
use source\core\grid\GridView;
use source\LuLu;
use source\models\DictCategory;
use yii\helpers\Url;
use source\libs\Constants;
/* @var $this yii\web\View */
/* @var $searchModel source\models\search\DictSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$category = LuLu::getGetValue('category');
$categoryModel = DictCategory::findOne(['id' => $category]);
$this->title = '字典';
$this->params['breadcrumbs'][] = $this->title;
?>

<?php 
$this->toolbars([Html::a('返回', ['/dict/dict-category'], ['class' => 'btn btn-xs btn-primary mod-site-save']), Html::a('新建', ['create', 'category' => $category], ['class' => 'btn btn-xs btn-primary mod-site-save'])]);
?>


    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'source\\core\\grid\\IdColumn'], ['attribute' => 'name', 'width' => 'auto'], ['attribute' => 'value', 'format' => 'ntext', 'width' => 'auto'], ['class' => 'source\\core\\grid\\SortColumn'], ['class' => 'source\\core\\grid\\StatusColumn'], ['class' => 'source\\core\\grid\\ActionColumn', 'queryParams' => ['view' => ['category' => $category]]]]]);