当前位置: 首页>>代码示例>>PHP>>正文


PHP ArrayHelper::treeTosingle方法代码示例

本文整理汇总了PHP中yii\helpers\ArrayHelper::treeTosingle方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::treeTosingle方法的具体用法?PHP ArrayHelper::treeTosingle怎么用?PHP ArrayHelper::treeTosingle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\helpers\ArrayHelper的用法示例。


在下文中一共展示了ArrayHelper::treeTosingle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionIndex

 /**
  * 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()]);
 }
开发者ID:lurongze,项目名称:uii20160328,代码行数:31,代码来源:MenuController.php

示例2: findlist

 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;
 }
开发者ID:lurongze,项目名称:uii20160328,代码行数:16,代码来源:Menu.php


注:本文中的yii\helpers\ArrayHelper::treeTosingle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。