public static function getAllCategories($type) { $ret = []; $categories = Category::findAll(['type' => $type]); foreach ($categories as $cate) { $ret[$cate['id']] = $cate['name']; } return $ret; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::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(['id' => $this->id, 'type' => $this->type, 'sort_num' => $this->sort_num]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'note', $this->note]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\grid\GridView; use source\LuLu; use app\modules\rbac\models\Category; /* @var $this yii\web\View */ /* @var $searchModel app\modules\rbac\models\search\CategorySearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $type = LuLu::getGetValue('type'); $this->title = Category::getTypes($type); $this->params['breadcrumbs'][] = $this->title; ?> <div class="category-index"> <p> <?php echo Html::a('新建分类', ['create', 'type' => $type], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'name', 'sort_num', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use app\modules\rbac\models\Category; /* @var $this yii\web\View */ /* @var $model app\modules\rbac\models\Role */ /* @var $form yii\widgets\ActiveForm */ $categories = Category::getAllCategories(Category::Type_Role); ?> <div class="role-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'key')->textInput(['maxlength' => 64, 'readonly' => $model->isNewRecord ? false : true]); ?> <?php echo $form->field($model, 'category_id')->dropDownList($categories); ?> <?php echo $form->field($model, 'name')->checkboxList(['0' => '早', '2' => 'aa', '3' => 'dd']); ?> <?php echo $form->field($model, 'note')->textarea(['rows' => 6]);
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use app\modules\rbac\models\Category; use app\modules\rbac\models\Permission; /* @var $this yii\web\View */ /* @var $model app\modules\rbac\models\Permission */ /* @var $form yii\widgets\ActiveForm */ $categories = Category::getAllCategories(Category::Type_Permission); ?> <div class="permission-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'key')->textInput(['maxlength' => 64, 'readonly' => $model->isNewRecord ? false : true]); ?> <?php echo $form->field($model, 'category_id')->dropDownList($categories); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => 64]); ?> <?php
<div>规则管理</div> <ul> <li><?php echo Html::a('新建规则', ['rule/create']); ?> </li> <li><?php echo Html::a('管理分类', ['category/index', 'type' => Category::Type_Rule]); ?> </li> <li><?php echo Html::a('全部', ['rule/index']); ?> </li> <?php $categories = Category::findAll(['type' => Category::Type_Rule]); foreach ($categories as $category) { ?> <li><?php echo Html::a($category['name'], ['rule/index', 'category_id' => $category['id']]); ?> </li> <?php } ?> </ul> </div> </div> <div class="col-md-10">
<?php use yii\helpers\Html; use app\modules\rbac\models\Category; use source\LuLu; /* @var $this yii\web\View */ /* @var $model app\modules\rbac\models\Category */ $type = $model->type; $this->title = '修改分类: ' . ' ' . $model->name; $this->params['breadcrumbs'][] = ['label' => Category::getTypes($type), 'url' => ['index', 'type' => $type]]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="category-update"> <?php echo $this->render('_form', ['model' => $model]); ?> </div>
/** * Finds the Category model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Category::findOne(['id' => $id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }