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


PHP CGlobal::categoriesTree方法代碼示例

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


在下文中一共展示了CGlobal::categoriesTree方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getCategoriesTree

 static function getCategoriesTree($get_direct = false, $hide = false)
 {
     if (!CGlobal::$categoriesTree) {
         self::getCats();
         $categories = array();
         if ($get_direct) {
             $topcat = array();
             $subcatlv2 = array();
             $sql = 'SELECT * FROM category';
             if ($hide) {
                 $sql .= ' WHERE status != "HIDE" AND category.ref_id = 0';
             }
             $sql .= ' ORDER BY parent_id, position';
             $re = DB::query($sql);
             if ($re) {
                 while ($cat = mysql_fetch_assoc($re)) {
                     if ($cat['status'] == 'HIDE') {
                         $cat['name'] .= ' (đã ẩn)';
                     }
                     if ($cat['parent_id']) {
                         $subcatlv2[$cat['parent_id']][$cat['id']] = $cat;
                     } else {
                         $topcat[$cat['id']] = $cat;
                     }
                 }
             }
             $subcat = array();
             foreach ($topcat as $cat) {
                 if (isset($subcatlv2[$cat['id']])) {
                     foreach ($subcatlv2[$cat['id']] as $sc) {
                         $subcat[$sc['id']] = $sc;
                         //if current sub category level 2
                     }
                     $cat['childs'] = $subcat;
                     $categories[$cat['id']] = $cat;
                     $subcat = array();
                 }
             }
         } else {
             if (CGlobal::$subCategories) {
                 $subcat = CGlobal::$subCategories;
                 foreach ($subcat as $id => $sub_cat) {
                     if (isset(CGlobal::$allCategories[$id])) {
                         $cat = CGlobal::$allCategories[$id];
                         if ($cat['ref_id'] == 0) {
                             $childs = array();
                             foreach ($sub_cat as $sid => $cat2) {
                                 if ($cat2['ref_id'] == 0) {
                                     $childs[$sid] = $cat2;
                                 }
                             }
                             $cat['childs'] = $childs;
                             $categories[$id] = $cat;
                         }
                     }
                 }
             }
         }
         CGlobal::$categoriesTree = $categories;
     }
     //echo "<pre>";
     //print_r(CGlobal::$categoriesTree);
     return CGlobal::$categoriesTree;
 }
開發者ID:duynhan07,項目名稱:elink,代碼行數:64,代碼來源:AZLib.php


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