當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ArrayHelper::createTree方法代碼示例

本文整理匯總了PHP中yii\helpers\ArrayHelper::createTree方法的典型用法代碼示例。如果您正苦於以下問題:PHP ArrayHelper::createTree方法的具體用法?PHP ArrayHelper::createTree怎麽用?PHP ArrayHelper::createTree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\helpers\ArrayHelper的用法示例。


在下文中一共展示了ArrayHelper::createTree方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: run

 public function run()
 {
     $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();
     $data = ArrayHelper::createTree($menuList);
     $plist = ArrayHelper::treeGetplist($data, \Yii::$app->request->get('mid'));
     //        UHelper::output($plist);
     return $this->render('beyondmenu', ['data' => $data, 'plist' => $plist, 'route' => \Yii::$app->controller->route]);
 }
開發者ID:lurongze,項目名稱:uii20160328,代碼行數:8,代碼來源:BeyondmenuWidget.php

示例3: 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::createTree方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。