Esempio n. 1
0
 /**
  * Lists all Menu models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new MenuSearch();
     $MenuSearch = Yii::$app->request->get('MenuSearch');
     if (!$MenuSearch) {
         $menuList = Menu::find()->where(['uid' => Yii::$app->user->getId()])->leftJoin('{{%plug}}', '{{%plug}}.id={{%menu}}.type')->select('{{%menu}}.*,{{%plug}}.name as typename,{{%plug}}.controller as controller')->orderBy('sort_order')->asArray()->all();
         $menuList = ArrayHelper::createTree($menuList);
         $menuList = ArrayHelper::treeTosingle($menuList);
         foreach ($menuList as $key => $item) {
             if (!empty($item['children'])) {
                 $menuList[$key]['is_bottom'] = 0;
             } else {
                 $menuList[$key]['is_bottom'] = 1;
             }
             unset($menuList[$key]['children']);
         }
         $render = 'index';
     } else {
         //搜索的时候
         $menuList = Menu::find()->where(['uid' => Yii::$app->user->getId()])->leftJoin('{{%plug}}', '{{%plug}}.id={{%menu}}.type')->select('{{%menu}}.*,{{%plug}}.name as typename,{{%plug}}.controller as controller')->orderBy('sort_order')->andFilterWhere(['like', '{{%menu}}.title', $MenuSearch['title']])->andFilterWhere(['{{%menu}}.type' => $MenuSearch['type']])->asArray()->all();
         //                echo $menuList;die;
         $render = 'filter';
     }
     $model = $menuList;
     $dataProvider = new \yii\data\ArrayDataProvider(['allModels' => $model, 'pagination' => ['pageSize' => 200], 'sort' => ['attributes' => ['id desc', 'sort_order asc']]]);
     return $this->render($render, ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'pluglist' => self::plugList()]);
 }
Esempio n. 2
0
 public static function findlist()
 {
     $menuList = Menu::find()->where(['uid' => Yii::$app->user->getId()])->orderBy('sort_order')->select('id,title,parentId,sort_order')->asArray()->all();
     $return = array();
     $return[0] = '一级菜单';
     $menuList = ArrayHelper::createTree($menuList);
     $menuList = ArrayHelper::treeTosingle($menuList);
     foreach ($menuList as $item) {
         $left = '';
         for ($i = 1; $i < $item['level']; $i++) {
             $left .= '  ';
         }
         $return[$item['id']] = $left . '└' . $item['title'];
     }
     return $return;
 }