/**
  * Finds the MenuCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return MenuCategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = MenuCategory::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 = MenuCategory::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;
 }
Example #3
0
<?php

use yii\helpers\Html;
use source\core\grid\GridView;
use source\LuLu;
use source\models\MenuCategory;
use yii\helpers\Url;
use source\libs\Constants;
/* @var $this yii\web\View */
/* @var $searchModel source\models\search\MenuCategorySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$category = LuLu::getGetValue('category');
$categoryModel = MenuCategory::findOne(['id' => $category]);
$this->title = $categoryModel['name'];
$this->addBreadcrumbs([['菜单管理', ['/menu']], [$categoryModel['name'], ['/menu/menu/index', 'category' => $category]], $this->title]);
?>

<?php 
$this->toolbars([Html::a('返回', ['/menu/menu-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', 'format' => 'html', 'width' => 'auto', 'value' => function ($model, $key, $index, $column) {
    return str_repeat(Constants::TabSize, $model->level) . Html::a($model->name, ['/menu/menu/update', 'id' => $model->id]);
}], ['attribute' => 'url', 'width' => '250px'], ['class' => 'source\\core\\grid\\CenterColumn', 'attribute' => 'targetText', 'width' => '50px'], ['class' => 'source\\core\\grid\\SortColumn'], ['class' => 'source\\core\\grid\\StatusColumn'], ['class' => 'source\\core\\grid\\ActionColumn', 'queryParams' => ['view' => ['category' => $category]]]]]);
?>