コード例 #1
0
 /**
  * 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 return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'discription', $this->discription])->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
コード例 #2
0
 /**
  * Finds the MenuCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $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.');
     }
 }
コード例 #3
0
ファイル: Menu.php プロジェクト: firdows/yii2-menu
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMenuCategory()
 {
     return $this->hasOne(MenuCategory::className(), ['id' => 'menu_category_id']);
 }
コード例 #4
0
ファイル: _form.php プロジェクト: firdows/yii2-menu
echo $form->field($model, 'parameter')->textInput(['maxlength' => true]);
?>
    </div> 
</div> 
<div class="row"> 
<div class="col-sm-6">  
        <?php 
echo $form->field($model, 'route')->textInput(['maxlength' => true]);
?>
    </div>   
    </div>   

<div class="row">   
    <div class="col-sm-6">
        <?php 
echo $form->field($model, 'menu_category_id')->dropDownList(MenuCategory::getList(), ['prompt' => Yii::t('app', 'เลือก')]);
?>
    </div>   
    <div class="col-sm-6">  
        <?php 
echo $form->field($model, 'parent_id')->dropDownList(Menu::getList(), ['prompt' => Yii::t('app', 'เลือก')]);
?>
    </div> 
</div> 


<div class="row">   
    <div class="col-sm-3">
        <?php 
echo $form->field($model, 'status')->dropDownList(Menu::getItemStatus(), ['prompt' => Yii::t('app', 'เลือก')]);
?>
コード例 #5
0
ファイル: index.php プロジェクト: firdows/yii2-menu
//use kartik\widgets\Select2;
/* @var $this yii\web\View */
/* @var $searchModel firdows\menu\models\MenuSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('menu', 'ระบบจัดการเมนู');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class='box box-info'>
    <div class='box-header'>
     <h3 class='box-title'><?php 
echo Html::encode($this->title);
?>
</h3>
    </div><!--box-header -->

    <div class='box-body pad'>

        <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'name', 'format' => 'html', 'value' => function ($model) {
    return Html::a($model->iconShow . ' ' . $model->title, ['/menu/default/view', 'id' => $model->id]);
}], ['attribute' => 'menu_category_id', 'filter' => MenuCategory::getList(), 'value' => function ($model) {
    return $model->menu_category_id ? $model->menuCategory->title : null;
}], ['attribute' => 'route', 'filter' => Menu::getRouterDistinct()], ['attribute' => 'parent_id', 'filter' => Menu::getParentDistinct(), 'value' => function ($model) {
    return $model->parentTitle;
}], ['attribute' => 'status', 'filter' => Menu::getItemStatus(), 'value' => 'statusLabel'], ['attribute' => 'items', 'filter' => Menu::getItemsListDistinct(), 'value' => 'itemsList', 'headerOptions' => ['width' => '200']], 'sort', ['class' => 'yii\\grid\\ActionColumn']]]);
?>


    </div><!--box-body pad-->
</div><!--box box-info-->